Skip to content
Merged
Changes from 2 commits
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
11 changes: 11 additions & 0 deletions jupyter_server/services/contents/fileio.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ def copy2_safe(src, dst, log=None):

like shutil.copy2, but log errors in copystat instead of raising
"""
# if src file is not writable, avoid creating a back-up
if not os.access(src, os.W_OK):
if log:
log.debug("Source file, %s, is not writeable", src, exc_info=True)
raise PermissionError(errno.EACCES, f"File is not writable: {src}")

shutil.copyfile(src, dst)
try:
shutil.copystat(src, dst)
Expand All @@ -52,6 +58,11 @@ async def async_copy2_safe(src, dst, log=None):

like shutil.copy2, but log errors in copystat instead of raising
"""
if not os.access(src, os.W_OK):
if log:
log.debug("Source file, %s, is not writeable", src, exc_info=True)
raise PermissionError(errno.EACCES, f"File is not writable: {src}")

await run_sync(shutil.copyfile, src, dst)
try:
await run_sync(shutil.copystat, src, dst)
Expand Down
Loading