Can you find a pattern to sync files knowing only dates and filenames?
- by Robert MacLean
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
The application never faults (see methods above).
That while the application is running the users can add and update files and those will be sync'd next time the application runs.
Files can be added to either the ted or bill directories.
File names cannot be altered.
The application will perform one sync per time it is run.
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.
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.
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.