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

Add log for debugging safe_copy issue during source_packaging #715

Closed
wants to merge 1 commit into from
Closed
Changes from all 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
39 changes: 39 additions & 0 deletions src/e3/fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -793,26 +793,52 @@ def safe_copy(src: FileInfo, dst: FileInfo) -> None:
:param src: the source FileInfo object
:param dst: the target FileInfo object
"""
e3.log.debug(f"safe_copy - debug : src={src} -> dst={dst}", exc_info=True)
if islink(src): # windows: no cover
e3.log.debug(f"safe_copy - debug : islink : {src}", exc_info=True)
linkto = os.readlink(src.path)
if not islink(dst) or os.readlink(dst.path) != linkto:
if dst.stat is not None:
rm(dst.path, recursive=True, glob=False)
os.symlink(linkto, dst.path)
e3.log.debug(
f"safe_copy - debug copy: islink : src={src} -> dst={dst}",
exc_info=True,
)
copystat(src, dst)
else:
e3.log.debug(
f"safe_copy - debug copy: NOT islink : src={src} -> dst={dst}",
exc_info=True,
)
if isdir(dst):
# dst directory will be replaced by a file having the same
# content as 'src'
e3.log.debug(
Copy link
Contributor

Choose a reason for hiding this comment

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

This comment is the same as above.
Better state isdir ?

f"safe_copy - debug : NOT islink : src={src}, isdir: dst ={dst}",
exc_info=True,
)
rm(dst.path, recursive=True, glob=False)
elif islink(dst):
e3.log.debug(
f"safe_copy - debug : NOT islink : src={src}, islink: dst ={dst}",
Copy link
Contributor

Choose a reason for hiding this comment

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

Here it's NOT islink({dst})

exc_info=True,
)
# dst symlink will be replaced by a file having the same
# content as 'src'
rm(dst.path, recursive=False, glob=False)

try:
if dst.basename != src.basename:
e3.log.debug(
f"safe_copy - debug : src:{src} file != dst:{dst} file",
Copy link
Contributor

Choose a reason for hiding this comment

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

Shoule mention the basename

exc_info=True,
)
if dst.stat is not None:
e3.log.debug(
f"safe_copy - debug: dst.stat is not None. dst={dst}",
exc_info=True,
)
# Case in which the destination file exists but does
# not have the same casing. In that case we delete the
# target file and redo a copy. This occurs for example
Expand All @@ -828,11 +854,24 @@ def safe_copy(src: FileInfo, dst: FileInfo) -> None:
with open(dst.path, "wb") as fdst:
shutil.copyfileobj(fsrc, fdst)
except OSError:
e3.log.debug(
f"safe_copy - debug: Got OSError!! src={src}, dst={dst}",
exc_info=True,
)
if dst.stat is not None:
e3.log.debug(
f"safe_copy - debug: OSError: dst.stat != None. dst={dst}",
exc_info=True,
)
rm(dst.path, glob=False)
with open(src.path, "rb") as fsrc:
with open(dst.path, "wb") as fdst:
shutil.copyfileobj(fsrc, fdst)

e3.log.debug(
f"safe_copy - debug copy: copystat src={src} -> dst={dst}",
exc_info=True,
)
copystat(src, dst)

def safe_mkdir(src: FileInfo, dst: FileInfo) -> None:
Expand Down
Loading