architecture.rst 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  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 renaming the
  107. local file, appending a conflict label and timestamp, and saving the remote file
  108. under the original file name.
  109. Example: Assume there is a conflict in message.txt because its contents have
  110. changed both locally and remotely since the last sync run. The local file with
  111. the local changes will be renamed to message_conflict-20160101-153110.txt and
  112. the remote file will be downloaded and saved as message.txt.
  113. Conflict files are always created on the client and never on the server.
  114. .. _ignored-files-label:
  115. Ignored Files
  116. -------------
  117. The ownCloud Client supports the ability to exclude or ignore certain files
  118. from the synchronization process. Some system wide file patterns that are used
  119. to exclude or ignore files are included with the client by default and the
  120. ownCloud Client provides the ability to add custom patterns.
  121. By default, the ownCloud Client ignores the following files:
  122. * Files matched by one of the patterns defined in the Ignored Files Editor
  123. * Files containing characters that do not work on certain file systems ``(`\, /, :, ?, *, ", >, <, |`)``.
  124. * Files starting with ``._sync_xxxxxxx.db`` and the old format ``.csync_journal.db``,
  125. as these files are reserved for journalling.
  126. If a pattern selected using a checkbox in the `ignoredFilesEditor-label` (or if
  127. a line in the exclude file starts with the character ``]`` directly followed by
  128. the file pattern), files matching the pattern are considered *fleeting meta
  129. data*. These files are ignored and *removed* by the client if found in the
  130. synchronized folder. This is suitable for meta files created by some
  131. applications that have no sustainable meaning.
  132. If a pattern ends with the forwardslash (``/``) character, only directories are
  133. matched. The pattern is only applied for directory components of filenames
  134. selected using the checkbox.
  135. To match filenames against the exclude patterns, the unix standard C library
  136. function fnmatch is used. This process checks the filename against the
  137. specified pattern using standard shell wildcard pattern matching. For more
  138. information, please refer to `The opengroup website
  139. <http://pubs.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_13_01>`_.
  140. The path that is checked is the relative path under the sync root directory.
  141. **Pattern and File Match Examples:**
  142. +-----------+------------------------------+
  143. | Pattern | File Matches |
  144. +===========+==============================+
  145. | ``~$*`` | ``~$foo``, ``~$example.doc`` |
  146. +-----------+------------------------------+
  147. | ``fl?p`` | ``flip``, ``flap`` |
  148. +-----------+------------------------------+
  149. | ``moo/`` | ``map/moo/``, ``moo/`` |
  150. +-----------+------------------------------+
  151. The Sync Journal
  152. ----------------
  153. The client stores the ETag number in a per-directory database, called the
  154. *journal*. This database is a hidden file contained in the directory to be
  155. synchronized.
  156. If the journal database is removed, the ownCloud Client CSync backend rebuilds
  157. the database by comparing the files and their modification times. This process
  158. ensures that both server and client are synchronized using the appropriate NTP
  159. time before restarting the client following a database removal.
  160. Custom WebDAV Properties
  161. ------------------------
  162. In the communication between client and server a couple of custom WebDAV properties
  163. were introduced. They are either needed for sync functionality or help have a positive
  164. effect on synchronization performance.
  165. This chapter describes additional xml elements which the server returns in response
  166. to a successful PROPFIND request on a file or directory. The elements are returned in
  167. the namespace oc.
  168. Server Side Permissions
  169. ------------------------
  170. The XML element ``<oc:permissions>`` represents the permission- and sharing state of the
  171. item. It is a list of characters, and each of the chars has a meaning as outlined
  172. in the table below:
  173. +----+----------------+-------------------------------------------+
  174. |Code| Resource | Description |
  175. +----+----------------+-------------------------------------------+
  176. | S | File or Folder | is shared |
  177. +----+----------------+-------------------------------------------+
  178. | R | File or Folder | can share (includes reshare) |
  179. +----+----------------+-------------------------------------------+
  180. | M | File or Folder | is mounted (like on DropBox, Samba, etc.) |
  181. +----+----------------+-------------------------------------------+
  182. | W | File | can write file |
  183. +----+----------------+-------------------------------------------+
  184. | C | Folder |can create file in folder |
  185. +----+----------------+-------------------------------------------+
  186. | K | Folder | can create folder (mkdir) |
  187. +----+----------------+-------------------------------------------+
  188. | D | File or Folder |can delete file or folder |
  189. +----+----------------+-------------------------------------------+
  190. | N | File or Folder | can rename file or folder |
  191. +----+----------------+-------------------------------------------+
  192. | V | File or Folder | can move file or folder |
  193. +----+----------------+-------------------------------------------+
  194. Example:
  195. <oc:permissions>RDNVCK</oc:permissions>
  196. File- or Directory Size
  197. -----------------------
  198. The XML element ``<oc:size>`` represents the file- or directory size in bytes. For
  199. directories, the size of the whole file tree underneath the directory is accumulated.
  200. Example:
  201. <oc:size>2429176697</oc:size>
  202. FileID
  203. ------
  204. The XML element ``<oc:id>`` represents the so called file ID. It is a non volatile string id
  205. that stays constant as long as the file exists. It is not changed if the file changes or
  206. is renamed or moved.
  207. Example:
  208. <oc:id>00000020oc5cfy6qqizm</oc:id>