Skip to content

Commit

Permalink
Explicitly clear hidden attribute for final files on MacOS
Browse files Browse the repository at this point in the history
Otherwise sometimes files will keep their hidden attribute after being
moved from a ".tmp" name to their final destination.
  • Loading branch information
I-Al-Istannen committed Nov 2, 2024
1 parent f5c4e82 commit 51496b6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ ambiguous situations.
- Crawling of nested courses
- Downloading of links with no target URL
- Handle row flex on description pages
- Files sometimes appearing as hidden on MacOS

## 3.6.0 - 2024-10-23

Expand Down
11 changes: 11 additions & 0 deletions PFERD/output_dir.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,17 @@ async def download(
return FileSinkToken(self, remote_path, path, local_path, heuristics, on_conflict)

def _update_metadata(self, info: DownloadInfo) -> None:
# Clear hidden attribute on MacOS
# chflags is only available on some unixes
if hasattr(os, "chflags"):
import stat
stat_result = os.stat(info.local_path)
# Not present on all unixes
if hasattr(stat_result, "st_flags"):
flags = getattr(stat_result, "st_flags")
flags &= ~stat.UF_HIDDEN
os.chflags(info.local_path, flags)

if mtime := info.heuristics.mtime:
mtimestamp = mtime.timestamp()
os.utime(info.local_path, times=(mtimestamp, mtimestamp))
Expand Down

0 comments on commit 51496b6

Please sign in to comment.