add: handle long filenames (#5201) (#5206)

(cherry picked from commit b779a117ab)

Co-authored-by: Ruslan Kuprieiev <[email protected]>
This commit is contained in:
mergify[bot]
2021-01-05 11:04:41 +02:00
committed by GitHub
co-authored by Ruslan Kuprieiev
parent 4bca30e4d6
commit c5fd3e3cff
2 changed files with 22 additions and 3 deletions
+3 -3
View File
@@ -177,7 +177,7 @@ class LocalTree(BaseTree):
move(from_info, to_info, mode=mode)
def copy(self, from_info, to_info):
tmp_info = to_info.parent / tmp_fname(to_info.name)
tmp_info = to_info.parent / tmp_fname("")
try:
System.copy(from_info, tmp_info)
os.chmod(tmp_info, self.file_mode)
@@ -188,7 +188,7 @@ class LocalTree(BaseTree):
def copy_fobj(self, fobj, to_info):
self.makedirs(to_info.parent)
tmp_info = to_info.parent / tmp_fname(to_info.name)
tmp_info = to_info.parent / tmp_fname("")
try:
copy_fobj_to_file(fobj, tmp_info)
os.chmod(tmp_info, self.file_mode)
@@ -236,7 +236,7 @@ class LocalTree(BaseTree):
return System.is_hardlink(path_info)
def reflink(self, from_info, to_info):
tmp_info = to_info.parent / tmp_fname(to_info.name)
tmp_info = to_info.parent / tmp_fname("")
System.reflink(from_info, tmp_info)
# NOTE: reflink has its own separate inode, so you can set permissions
# that are different from the source.
+19
View File
@@ -1,3 +1,4 @@
import errno
import filecmp
import logging
import os
@@ -951,3 +952,21 @@ def test_add_preserve_meta(tmp_dir, dvc):
meta: some metadata
"""
)
# NOTE: unless long paths are enabled on Windows, PATH_MAX and NAME_MAX
# are the same 260 chars, which makes the test unnecessarily complex
@pytest.mark.skipif(os.name == "nt", reason="unsupported on Windows")
def test_add_long_fname(tmp_dir, dvc):
name_max = os.pathconf(tmp_dir, "PC_NAME_MAX")
name = "a" * name_max
tmp_dir.gen({"data": {name: "foo"}})
# nothing we can do in this case, as the resulting dvcfile
# will definitely exceed NAME_MAX
with pytest.raises(OSError) as info:
dvc.add(os.path.join("data", name))
assert info.value.errno == errno.ENAMETOOLONG
dvc.add("data")
assert (tmp_dir / "data").read_text() == {name: "foo"}