-
Notifications
You must be signed in to change notification settings - Fork 19
Option to redownload file when the file on Moodle with the same path is modified #128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
On first look this seems like a good solution which avoids having to do more state management in syncmymoodle than necessary, thumbs up from my side |
|
One concern I have is, what if someone modified a file locally? For example added notes to a slide deck? They update syncmymoodle and suddenly experience data loss if a prof modifies the slide deck. Maybe we do need to do more state tracking on our side :( One solution would be that we use the old root to check if a file was modified locally, before re-downloading it.. and move the locally modified file to "file name.syncconflict.hash" or something similar then, we can avoid that issue. We might also consider adding a setting to ignore these updates for specific moodle rooms or similar. (Since there might be some weird ones which do weird stuff with course files?) |
|
We can also combine the solution mentioned by Septatrix with this approach, to avoid re-downloading files if they are synced for the first time with the root enabled. Maybe just comparing the exact byte size would be enough (and if bytes are off, handle it as a sync conflict since we can't know if a user modified it) |
If we really need to check local modification, then I think one way to do it is, as @septatrix mentioned, to make the
That assumes that before the first run, all the files are the updated versions, no? If the file is already updated on Moodle before the first run, and the local file is outdated, the file will never be updated if there are no future modification any more, e.g. previous semester courses, etc.
I'm not sure about this, because if it's just a simple text file, the chance of having the same size to the byte is very high, e.g. correction of spelling error. I think it might be hard to avoid redownload on first run. |
|
To do/ to solve:
|
|
Just to write it down here, proposed solution to the local modification overwrite avoidance (integrating septatrix's proposal from #77):
This might be the best of both worlds, since without the old root, we wouldn't know if differing |
Sounds good, and also to have the syncconflict resolution (i.e. move the old files)
Maybe this option can then be configured for each course seperately |
de0f91d to
e82c5c1
Compare
What do you mean with current and old root?
Yeah I like this a lot. Maybe even an option whether to move the old file to a new place or keep it and simply place the incoming file into a different place. I think both have their merit, think e.g. the "Recently opened" tab of programs. |
I think having an option for moving the incoming file would cause some headaches for us when doing state management, since now we have to also manage any number of new files which may get written to disk, and keep track of their states as well. I think having just the 3 options I proposed would be more than fine, maybe that fourth option can be added in a future PR if someone really wants/needs it. |
|
I have also fixed the main branch so that the linting checks now run through (flake8 can only be sensible addressed with a major future refactor) |
e82c5c1 to
f8596a1
Compare
Have you considered also storing the ETag when getting a file? If we store that in the root, we can accurately detect local file changes (without relying on timestaps/bytes). Also, if we see that the timestamp has changed on the server, we can request it with HEAD and check the etag against local sha1 hash to see if it has actually changed, and only then download. And if a client is doing this for the first time, i.e. has no cached root, but does have files downloaded, we can use the HEAD etag to compare local files vs moodle without redownloading everything. |
Old root is the
I'm implementing using ETag to compare when there is no cached |
But shouldn't we store the file hash/ ETag from the last completed file download/update in the root cache to be able to detect if a file was locally modified so we don't delete userdata when doing a file update? |
I believe when getting the content of a course, the ETags of the files are not sent. So we need to do a These are the metadata that we have, without doing additional network requests than what is currently implemented: |
|
Oh wait, I think I misunderstood. You mean when downloading a file, we save the ETag and use it to detect local changes on next run. We could do that, too I think. That would be safer than just using |
Nothing guarantees that it will remain the SHA1 hash, they could change that at any point, have done so in the past (IIRC it was MD5 before), and there have been talks in their bug tracker about changing it in the future (IIRC to SHA256) |
|
Let's just start with |
That's true, but even if they change the hash algorithm, it's not a big issue for us, if we maintain a local cache along with the corresponding local files, so we're not solely dependent on the ETag. That said, we should implement a check to detect if the hash algorithm has changed and raise an explicit error if it does. For After then updating the cached local state with the new hashes, we'll remain in sync with the updated Moodle version. Keeping track of hashes is mostly good for noticing local changes and not destroying data 😅 Maybe we also talking past each other, I agree that |
Some course admins update files with the same name at the same path. With this implementation of this feature, the script will dump a cache of the node tree
root_nodeafter every run. This cache is compared with the new node tree on the next run to identify which file is modified.The cache file is just a normal binary file, does not need any special maintenance.
Caveat:
selected_courses,skip_courses,only_sync_semesterorused_modules), and re-included afterwards, every file from that course or module will be treated as modified and redownloaded.Alternative solution to #77 instead of having to modify local file
mtime