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

utils/fs: checking files ownership in 'move' (#4348) #4832

Merged
merged 5 commits into from
Nov 12, 2020
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
10 changes: 7 additions & 3 deletions dvc/utils/fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,19 @@ def move(src, dst, mode=None):
dst = os.path.abspath(dst)
tmp = f"{dst}.{uuid()}"

try:
if mode is not None:
os.chmod(src, mode)
except OSError:
# File not owned by us, raise exception
danielfleischer marked this conversation as resolved.
Show resolved Hide resolved
raise DvcException(f"File not owned by user: {src}")

if os.path.islink(src):
shutil.copy(src, tmp)
os.unlink(src)
else:
shutil.move(src, tmp)

if mode is not None:
os.chmod(tmp, mode)

shutil.move(tmp, dst)


Expand Down