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
Show file tree
Hide file tree
Changes from 4 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
5 changes: 5 additions & 0 deletions dvc/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,11 @@ def __init__(self, path, hint=None):
)


class FileOwnershipError(DvcException):
def __init__(self, path):
super().__init__(f"file '{path}' not owned by user! ")


class DvcIgnoreInCollectedDirError(DvcException):
def __init__(self, ignore_dirname):
super().__init__(
Expand Down
14 changes: 10 additions & 4 deletions dvc/utils/fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import nanotime
from shortuuid import uuid

from dvc.exceptions import DvcException
from dvc.exceptions import DvcException, FileOwnershipError
from dvc.system import System
from dvc.utils import dict_md5

Expand Down Expand Up @@ -95,15 +95,21 @@ 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 as e:
if e.errno not in [errno.EACCES, errno.EPERM]:
raise
else:
raise FileOwnershipError(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