User Tools

Site Tools


access:file_directory_sync_algorithm

Keeping Files and Directories in Sync with Access

Moving forward we will want to keep selected local Projects in sync with Access. It should be possible for a user to manage projects locally on the desktop. This can be done using the Windows File Explorer or by using the Agtek Application Framework. If using the File Explorer the changes will only be visible locally. When the user launches the Agtek Application Framework and connects with Access any local changes will be able to be synchronized with Access. The Agtek Application Framework will also have the ability to manage projects and keep things in sync with the Access server.

File Synchronization Algorithm

The synchronization algorithm that we will be using is based on an approach described in an article written by Markus Unterwaditzer, “A simple synchronization algorithm” (https://unterwaditzer.net/2016/sync-algorithm.html)

This article describes a method to keep two sets of files in sync. The main idea is that three sets are maintained. The first is the files on the Server, the second are the files on the Client and the third is a Status set which contains a map of tuples. The status map allows lookup of Hashes for the files on the Client and Server. This allows us to determine if there have been any changes to the files on either the Client or Server. The following cases determine what to do to keep things in sync:

  1. Client set has file, Server set does not, Status set does not. This means that a new file was created on the client and needs added to the Server and Status sets. The opposite is true for the Server.
  2. Client set has file, Status set has file, Server set does not. This means that the file was deleted from the Server and therefore needs deleted from the client and status sets.
  3. File on Client and Server but not in Status. Look at the hash values for both files. If they match then add a Status set update. If they don't match then move to conflict resolution.
  4. File in Status but not in Client or Server then remove from Status.

As mentioned above, the Status set is a Map. The map key is the name of the file. The key is used to lookup a tuple which contains a Hash for the Client file and Server file. If the file being examined does not match the hash value on either the Client side or Server side then it has changed.

  1. If the Server file has changed and the Client file has not then copy the Server file to the Client and update the Status map Client hash.
  2. If the Client file has changed and the Server file has not then copy the Client file to the Server and update the Status map Server hash.
  3. If both the Client file and Server file have changed then we need to move to conflict resolution.

Conflict Resolution

If there are changes to files on both the client and server then we need to prompt the user to resolve the conflict. The user can accept one change over the other or keep both changes by putting one into a new file. The results of the user decisions will be synchronized.

access/file_directory_sync_algorithm.txt · Last modified: 2020/08/06 20:10 by timm