mstock / RoomAssets-App-Sync

Other
0 stars 0 forks source link

Directory permission problems #11

Closed joto closed 7 months ago

joto commented 7 months ago

Sometimes the talk directories have 0644 permissions instead of 0755 which can lead to all sorts of problems, even killing the script because it can't write into that directory any more. It is only a few directories where this happens and if you remove them and start again, all is fine. I have no idea what trigger that problem.

mstock commented 7 months ago

This seems to be caused by LWP::UserAgent's mirror($url, $filename) method when it gets passed the path to an existing directory as $filename instead of an actual file name and when the resource that should be downloaded is newer (or the server doesn't care about If-Modified-Since) than the existing directory (since otherwise, the download is not performed as the server should reply with a 304 Not Modified status).

In this case, a temporary file gets created (either inside or next to the directory, depending on if the target path passed to mirror() ended with a / or not) where the downloaded data is stored which is then moved to the $filename (a directory in this case), which also results in the file name still ending with a random string with leading - from creating the temporary file. Since the temporary files created by File::Temp usually only get minimal permissions (0600), mirror() performs a chmod() on the $filename (i.e. the directory instead of the actual file in this case) using 0666 masked with the umask, which would explain the 0644 you saw.

As the script is skipping the download since f818b5890b if no non-empty target file name could be determined, this should actually not be happening anymore since that commit. The aforementioned change was implemented in an attempt to fix #10. If this still happens, I'd have to take another look, as I'd apparently still be missing something.

joto commented 7 months ago

I can't test this any more in a real environment, so lets assume this is fixed. Thanks!