Can you find a pattern to sync files knowing only dates and filenames?

Posted by Robert MacLean on Stack Overflow See other posts from Stack Overflow or by Robert MacLean
Published on 2010-04-13T16:43:49Z Indexed on 2010/04/13 17:43 UTC
Read the original article Hit count: 390

Filed under:
|
|

Imagine if you will a operating system that had the following methods for files

  • Create File: Creates (writes) a new file to disk. Calling this if a file exists causes a fault.
  • Update File: Updates an existing file. Call this if a file doesn't exist causes a fault.
  • Read File: Reads data from a file.
  • Enumerate files: Gets all files in a folder.

Files themselves in this operating system only have the following meta data:

  • Created Time: The original date and time the file was created, by the Create File method.
  • Modified Time: The date and time the file was last modified by the Update File method. If the file has never been modified, this will equal the Create Time.

You have been given the task of writing an application which will sync the files between two directories (lets call them bill and ted) on a machine. However it is not that simple, the client has required that

  1. The application never faults (see methods above).
  2. That while the application is running the users can add and update files and those will be sync'd next time the application runs.
  3. Files can be added to either the ted or bill directories.
  4. File names cannot be altered.
  5. The application will perform one sync per time it is run.
  6. The application must be almost entirely in memory, in other words you cannot create a log of filenames and write that to disk and then check that the next time.
  7. The exception to point 6 is that you can store date and times between runs. Each date/time is associated with a key labeled A through J (so you have 10 to use) so you can compare keys between runs.
  8. There is no way to catch exceptions in the application.


Answer will be accepted based on the following conditions:

  • First answer to meet all requirements will be accepted.
  • If there is no way to meet all requirements, the answer which ensures the smallest amount of missed changes per sync will be accepted.
  • A bounty will be created (100 points) as soon as possible for the prize. The winner will be selected one day before the bounty ends.

Please ask questions in the comments and I will gladly update and refine the question on those.

© Stack Overflow or respective owner

Related posts about synchronization

Related posts about theory