Skip to content
This repository has been archived by the owner on Oct 4, 2024. It is now read-only.

Commit

Permalink
honour umask in downloaded files
Browse files Browse the repository at this point in the history
  • Loading branch information
gilesknap committed Jul 31, 2019
1 parent 8eab21d commit 27407ac
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions gphotos/GooglePhotosDownload.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ def __init__(self, api: RestClient, root_folder: Path, db: LocalData):
self.pool_future_to_media = {}
self.bad_ids = BadIds(self._root_folder)

self.current_umask = os.umask(7)
os.umask(self.current_umask)

self._session = requests.Session()
retries = Retry(total=5,
backoff_factor=0.1,
Expand Down Expand Up @@ -220,6 +223,7 @@ def do_download_file(self, base_url: str, media_item: DatabaseMedia):
os.utime(str(local_full_path),
(Utils.safe_timestamp(media_item.modify_date),
Utils.safe_timestamp(media_item.create_date)))
os.chmod(str(local_full_path), 0o666 & ~self.current_umask)
except KeyboardInterrupt:
log.debug("User cancelled download thread")
raise
Expand Down
2 changes: 1 addition & 1 deletion test/test_credentials/.gphotos.token
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"access_token": "ya29.Gl1VB3ETG6Q7KNV5pEPAkwNSPBQTfN0hqCWL738yozvKO2iFrRmNSTsQNhweyqZRaXY7OgCjr7zqv6QdEeIuB_2f_lkezhls1E_COGbnkwOKrEGbhdgqpsNvuG8YVo0", "expires_in": 3600, "scope": ["https://www.googleapis.com/auth/photoslibrary.sharing", "https://www.googleapis.com/auth/photoslibrary.readonly"], "token_type": "Bearer", "expires_at": 1564523771.4965656, "refresh_token": "1/HG0feqbbu7FZLjztEbGneV0Jz2aNoiNYuFIHvcZ9MgQ"}
{"access_token": "ya29.Gl1WB4CwD_sE9T0LnmkMSSjesZknrhxOdf0sJ-uxlFOgAFfPz29YbCdn05RuQ4XZEGXXdh0ykeM3HVk0ufMQTxElwBPFmvN4OmzwcAgRNI-L4DWGszwEfyt1XHt_vOo", "expires_in": 3600, "scope": ["https://www.googleapis.com/auth/photoslibrary.sharing", "https://www.googleapis.com/auth/photoslibrary.readonly"], "token_type": "Bearer", "expires_at": 1564572955.0487018, "refresh_token": "1/HG0feqbbu7FZLjztEbGneV0Jz2aNoiNYuFIHvcZ9MgQ"}

3 comments on commit 27407ac

@foscoj
Copy link

@foscoj foscoj commented on 27407ac Oct 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to chmod here? On TrueNAS with a CIFS (smb/windows share) chmod is not permitted and only works sometimes.

@gilesknap
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The umask is not honoured otherwise. As I remember the file is initially created in tmp with fixed permissions. On linux filesystems users expect the user mask to define group and all user permissions and this was not happening.

It should be pretty easy to skip this step for some filesystems for which it is not relevant.

@foscoj
Copy link

@foscoj foscoj commented on 27407ac Oct 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx for your quick answer! As the ACL on the share is open anyway, the umask should not matter. Cloned the repo locally and skipped this line, script is working like a charm, many many thanks for your effort!

Please sign in to comment.