Synchronization Cases
| Notation E = File or dir exists (not updated) N = File or dir doesn't exist or has been removed U = File has been updated (we don't care if a dir is updated, only if its contents are updated) |
If it's a file
| Alfresco | FileSystem | Operation |
|---|---|---|
| E | N | Copy to FS |
| E | E | Do nothing |
| U | E | Copy to FS |
| E | U | Copy to FS |
| N | E | Remove from FS |
If it's a directory
| Alfresco | FileSystem | Operation |
|---|---|---|
| E | N | Copy entire dir tree to FS |
| E | E | Synchronize recursively |
| U | E | Synchronize recursively |
| E | U | Synchronize recursively |
| N | E | Remove entire dir tree from FS |
If it's a file in Alfresco but a dir in the FS, or a dir in Alfresco but a file in the FS
Delete whatever is in the FS and copy whatever is in Alfresco
Algorithm
function synchronize(avmNode, fsFile) if avmNode.exists() && !fsFile.exists() if avmNode.isFile() copyToFs(fsFile, avmNode.getContent()) else copyTreeToFs(fsFile, avmNode) else if avmNode.exists() && fsFile.exists() if avmNode.isFile() && fsFile.isFile() if updated(avmNode, fsFile) // Can be done by date comparison, file size comparison or checksum comparison copyToFs(fsFile, avmNode.getContent()) else if avmNode.isDir() && fsFile.isDir() for avmNodeChild in avmNode.getChildren() fsFileChild = fsFile.getChild(avmNodeChild.getName()) synchronize(avmNodeChild, fsFileChild) else // This could mean that someone deleted a dir and created a file with the same name, or vice versa. deleteFromFs(file) if avmNode.isFile() copyToFs(fsFile, avmNode.getContent()) else copyTreeToFs(fsFile, avmNode) else if !avmNode.exists() && fsFile.exists() deleteFromFs(fsFile)