mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-11 15:28:27 +01:00
add: handle long filenames (#5201)
This commit is contained in:
+3
-3
@@ -174,7 +174,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)
|
||||
@@ -185,7 +185,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)
|
||||
@@ -229,7 +229,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.
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import errno
|
||||
import filecmp
|
||||
import logging
|
||||
import os
|
||||
@@ -972,3 +973,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"}
|
||||
|
||||
Reference in New Issue
Block a user