architecture.rst 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. Appendix B: History and Architecture
  2. ====================================
  3. .. index:: architecture
  4. ownCloud provides desktop sync clients to synchronize the contents of local
  5. directories from computers, tablets, and handheld devices to the ownCloud
  6. server.
  7. Synchronization is accomplished using csync_, a bidirectional file
  8. synchronizing tool that provides both a command line client as well as a
  9. library. A special module for csync was written to synchronize with the
  10. ownCloud built-in WebDAV server.
  11. The ownCloud Client software is written in C++ using the `Qt Framework`_. As a
  12. result, the ownCloud Client runs on Linux, Windows, and MacOS.
  13. .. _csync: http://www.csync.org
  14. .. _`Qt Framework`: http://www.qt-project.org
  15. The Synchronization Process
  16. ---------------------------
  17. The process of synchronization keeps files in two separate repositories the
  18. same. When synchronized:
  19. - If a file is added to one repository it is copied to the other synchronized repository.
  20. - When a file is changed in one repository, the change is propagated to any other
  21. synchronized repository.
  22. - If a file is deleted in one repository, it is deleted in any other.
  23. It is important to note that the ownCloud synchronization process does not use
  24. a typical client/server system where the server is always master. This is a
  25. major difference between the ownCloud synchronization process and other systems
  26. like a file backup, where only changes to files or folders and the addition of
  27. new files are propagated, but these files and folders are never deleted unless
  28. explicitly deleted in the backup.
  29. During synchronization, the ownCloud Client checks both repositories for
  30. changes frequently. This process is referred to as a *sync run*. In between
  31. sync runs, the local repository is monitored by a file system monitoring
  32. process that starts a sync run immediately if something was edited, added, or
  33. removed.
  34. Synchronization by Time versus ETag
  35. -----------------------------------
  36. .. index:: time stamps, file times, etag, unique id
  37. Until the release of ownCloud 4.5 and ownCloud Client 1.1, the ownCloud
  38. synchronization process employed a single file property -- the file modification
  39. time -- to decide which file was newer and needed to be synchronized to the
  40. other repository.
  41. The *modification timestamp* is part of the files metadata. It is available on
  42. every relevant filesystem and is the typical indicator for a file change.
  43. Modification timestamps do not require special action to create, and have a
  44. general meaning. One design goal of csync is to not require a special server
  45. component. This design goal is why csync was chosen as the backend component.
  46. To compare the modification times of two files from different systems, csync
  47. must operate on the same base. Before ownCloud Client version 1.1.0, csync
  48. required both device repositories to run on the exact same time. This
  49. requirement was achieved through the use of enterprise standard `NTP time
  50. synchronization`_ on all machines.
  51. Because this timing strategy is rather fragile without the use of NTP, ownCloud
  52. 4.5 introduced a unique number (for each file?) that changes whenever the file
  53. changes. Although this number is a unique value, it is not a hash of the file.
  54. Instead, it is a randomly chosen number, that is transmitted in the Etag_
  55. field. Because the file number changes if the file changes, its use is
  56. guaranteed to determine if one of the files has changed and, thereby, launching
  57. a synchronization process.
  58. .. note:: ownCloud Client release 1.1 and later requires file ID capabilities
  59. on the ownCloud server. Servers that run with release earlier than 4.5.0 do
  60. not support using the file ID functionality.
  61. Before the 1.3.0 release of the Desktop Client, the synchronization process
  62. might create false conflict files if time deviates. Original and changed files
  63. conflict only in their timestamp, but not in their content. This behavior was
  64. changed to employ a binary check if files differ.
  65. Like files, directories also hold a unique ID that changes whenever one of the
  66. contained files or directories is modified. Because this is a recursive
  67. process, it significantly reduces the effort required for a synchronization
  68. cycle, because the client only analyzes directories with a modified ID.
  69. The following table outlines the different synchronization methods used,
  70. depending on server/client combination:
  71. .. index:: compatiblity table
  72. +--------------------+-------------------+----------------------------+
  73. | Server Version | Client Version | Sync Methods |
  74. +====================+===================+============================+
  75. | 4.0.x or earlier | 1.0.5 or earlier | Time Stamp |
  76. +--------------------+-------------------+----------------------------+
  77. | 4.0.x or earlier | 1.1 or later | n/a (incompatible) |
  78. +--------------------+-------------------+----------------------------+
  79. | 4.5 or later | 1.0.5 or earlier | Time Stamp |
  80. +--------------------+-------------------+----------------------------+
  81. | 4.5 or later | 1.1 or later | File ID, Time Stamp |
  82. +--------------------+-------------------+----------------------------+
  83. We strongly recommend using ownCloud Server release 4.5 or later when using
  84. ownCloud Client 1.1 or later. Using an incompatible time stamp-based
  85. synchronization mechanism can lead to data loss in rare cases, especially when
  86. multiple clients are involved and one utilizes a non-synchronized NTP time.
  87. .. _`NTP time synchronization`: http://en.wikipedia.org/wiki/Network_Time_Protocol
  88. .. _Etag: http://en.wikipedia.org/wiki/HTTP_ETag
  89. Comparison and Conflict Cases
  90. -----------------------------
  91. As mentioned above, during a *sync run* the client must first detect if one of
  92. the two repositories have changed files. On the local repository, the client
  93. traverses the file tree and compares the modification time of each file with an
  94. expected value stored in its database. If the value is not the same, the client
  95. determines that the file has been modified in the local repository.
  96. .. note:: On the local side, the modification time is a good attribute to use for
  97. detecting changes, because
  98. the value does not depend on time shifts and such.
  99. For the remote (that is, ownCloud server) repository, the client compares the
  100. ETag of each file with its expected value. Again, the expected ETag value is
  101. queried from the client database. If the ETag is the same, the file has not
  102. changed and no synchronization occurs.
  103. In the event a file has changed on both the local and the remote repository
  104. since the last sync run, it can not easily be decided which version of the file
  105. is the one that should be used. However, changes to any side will not be lost. Instead,
  106. a *conflict case* is created. The client resolves this conflict by creating a
  107. conflict file of the older of the two files and saving the newer file under the
  108. original file name. Conflict files are always created on the client and never
  109. on the server. The conflict file uses the same name as the original file, but
  110. is appended with the timestamp of the conflict detection.
  111. .. _ignored-files-label:
  112. Ignored Files
  113. -------------
  114. The ownCloud Client supports the ability to exclude or ignore certain files
  115. from the synchronization process. Some system wide file patterns that are used
  116. to exclude or ignore files are included with the client by default and the
  117. ownCloud Client provides the ability to add custom patterns.
  118. By default, the ownCloud Client ignores the following files:
  119. * Files matched by one of the patterns defined in the Ignored Files Editor
  120. * Files containing characters that do not work on certain file systems ``(`\, /, :, ?, *, ", >, <, |`)``.
  121. * Files starting with ``._sync_xxxxxxx.db`` and the old format ``.csync_journal.db``,
  122. as these files are reserved for journalling.
  123. If a pattern selected using a checkbox in the `ignoredFilesEditor-label` (or if
  124. a line in the exclude file starts with the character ``]`` directly followed by
  125. the file pattern), files matching the pattern are considered *fleeting meta
  126. data*. These files are ignored and *removed* by the client if found in the
  127. synchronized folder. This is suitable for meta files created by some
  128. applications that have no sustainable meaning.
  129. If a pattern ends with the forwardslash (``/``) character, only directories are
  130. matched. The pattern is only applied for directory components of filenames
  131. selected using the checkbox.
  132. To match filenames against the exclude patterns, the unix standard C library
  133. function fnmatch is used. This process checks the filename against the
  134. specified pattern using standard shell wildcard pattern matching. For more
  135. information, please refer to `The opengroup website
  136. <http://pubs.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_13_01>`_.
  137. The path that is checked is the relative path under the sync root directory.
  138. **Pattern and File Match Examples:**
  139. +-----------+------------------------------+
  140. | Pattern | File Matches |
  141. +===========+==============================+
  142. | ``~$*`` | ``~$foo``, ``~$example.doc`` |
  143. +-----------+------------------------------+
  144. | ``fl?p`` | ``flip``, ``flap`` |
  145. +-----------+------------------------------+
  146. | ``moo/`` | ``map/moo/``, ``moo/`` |
  147. +-----------+------------------------------+
  148. The Sync Journal
  149. ----------------
  150. The client stores the ETag number in a per-directory database, called the
  151. *journal*. This database is a hidden file contained in the directory to be
  152. synchronized.
  153. If the journal database is removed, the ownCloud Client CSync backend rebuilds
  154. the database by comparing the files and their modification times. This process
  155. ensures that both server and client are synchronized using the appropriate NTP
  156. time before restarting the client following a database removal.
  157. Custom WebDAV Properties
  158. ------------------------
  159. In the communication between client and server a couple of custom WebDAV properties
  160. were introduced. They are either needed for sync functionality or help have a positive
  161. effect on synchronization performance.
  162. This chapter describes additional xml elements which the server returns in response
  163. to a successful PROPFIND request on a file or directory. The elements are returned in
  164. the namespace oc.
  165. Server Side Permissions
  166. ------------------------
  167. The XML element ``<oc:permissions>`` represents the permission- and sharing state of the
  168. item. It is a list of characters, and each of the chars has a meaning as outlined
  169. in the table below:
  170. +----+----------------+-------------------------------------------+
  171. |Code| Resource | Description |
  172. +----+----------------+-------------------------------------------+
  173. | S | File or Folder | is shared |
  174. +----+----------------+-------------------------------------------+
  175. | R | File or Folder | can share (includes reshare) |
  176. +----+----------------+-------------------------------------------+
  177. | M | File or Folder | is mounted (like on DropBox, Samba, etc.) |
  178. +----+----------------+-------------------------------------------+
  179. | W | File | can write file |
  180. +----+----------------+-------------------------------------------+
  181. | C | Folder |can create file in folder |
  182. +----+----------------+-------------------------------------------+
  183. | K | Folder | can create folder (mkdir) |
  184. +----+----------------+-------------------------------------------+
  185. | D | File or Folder |can delete file or folder |
  186. +----+----------------+-------------------------------------------+
  187. | N | File or Folder | can rename file or folder |
  188. +----+----------------+-------------------------------------------+
  189. | V | File or Folder | can move file or folder |
  190. +----+----------------+-------------------------------------------+
  191. Example:
  192. <oc:permissions>RDNVCK</oc:permissions>
  193. File- or Directory Size
  194. -----------------------
  195. The XML element ``<oc:size>`` represents the file- or directory size in bytes. For
  196. directories, the size of the whole file tree underneath the directory is accumulated.
  197. Example:
  198. <oc:size>2429176697</oc:size>
  199. FileID
  200. ------
  201. The XML element ``<oc:id>`` represents the so called file ID. It is a non volatile string id
  202. that stays constant as long as the file exists. It is not changed if the file changes or
  203. is renamed or moved.
  204. Example:
  205. <oc:id>00000020oc5cfy6qqizm</oc:id>