I’ve found a bug in the way the Files.rs synchronisation works, which I believe is what has been causing unusual bugs for a while (people complaining that FilesContainers aren’t updating or that their NRS is showing “old version”, etc.)
safe-api/files.rs considers three factors when deciding whether or not it should upload a file:
- Are we using the force parameter (in which case all files are updated)
- Is the file type the same as the previous file type
- Is the length of the the file contents the same as the previous length
In scenarios where preprocessors are being used to generate files (for instance, using a bundling agent such as Webpack) it’s very likely that an index.html
file will have the same string length after an update (the file names of the linked Javascript files will be the only changed data, and these tend to be the same length, 8-10 random characters. This is traditionally used for “cache punching” when you want CDNs to deliver new versions of files exclusively).
Because the sync test is content agnostic, these kinds of files will never be updated.
This seems like a bug to me, in my opinion the contents of the file (as long as the file is some reasonable size, say under 10MB) should be diffed to see if there have been any substantial changes (or perhaps some sort of file hash).
To combat a likely off-the-cuff response: There is a compare_file_content
on the files_map_sync
function which is being passed as true, but the value of compare_file_content
only dictates error states and checks against the file size, not whether the files contents themselves are actually diffed.
Reproducability
Create a FilesContainer in the CLI, then:
- Create a file named
test.example
and give it the contentf
- Sync the file up to the FilesContainer you created earlier without the force flag set
You will get the following success:
FilesContainer synced up (version XXX): "XORURL"
+ ../path/to/test.example safe://XORURL
- Update
test.example
to contain the contentb
- Sync the file up to the FilesContainer you created earlier without the force flag set
You will get the following error:
No changes were required, source location is already in sync with FilesContainer (version XXX) at: "XorURL"
Cheers,
Shane