Skip to content
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

Download Failure Resilience #956

Merged
merged 7 commits into from
Nov 8, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Clarify the file permissions for downloaded files
- Along with explaining umask usage, the default file permissions were
  updated from 664 to 666 to better mirror `open()`.
  • Loading branch information
rmartin16 committed Nov 7, 2022
commit a678266cc6cc237135d954646049480f057f76f2
18 changes: 16 additions & 2 deletions src/briefcase/integrations/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,24 @@ def _fetch_and_write_content(self, response, filename):
temp_file.write(data)
progress_bar.update(task_id, advance=len(data))

# This file move short circuits to a file rename when the source and
# destination are on the same filesystem; therefore, it should complete
# quite quickly even for large files.
self.tools.shutil.move(temp_file.name, filename)
rmartin16 marked this conversation as resolved.
Show resolved Hide resolved
# retrieving the current umask requires changing it...
# Temporary files are created with only read/write permissions for the
# file's owner (i.e. 600); to match the behavior of file creation using
# ``open(..., w)``, the downloaded file's permissions are updated for
# the group and world to have read/write permissions as well. Finally,
# (as with ``open()``) the system's umask is respected. The current
# umask is only available as the return value to updating the umask...
# Updating the umask affects the current process, including all threads.
# A umask value represents permissions that should be denied; so, 022
# denies write permissions to the group and world. A 022 umask is a
# common default among supporting systems.
os.umask(current_umask := os.umask(0o022))
self.tools.os.chmod(filename, 0o664 & ~current_umask)
# The umask is applied by inverting it and bitwise ANDing the default
# permissions...thus masking out permissions that should be denied.
self.tools.os.chmod(filename, 0o666 & ~current_umask)
finally:
# Ensure the temporary file is deleted; this file may still
# exist if the download fails or the user sends CTRL+C.
Expand Down