Skip to content
Merged
Show file tree
Hide file tree
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
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
16 changes: 11 additions & 5 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)
_unlink(src, _chmod)
else:
shutil.move(src, tmp)

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

shutil.move(tmp, dst)


Expand Down