Fixes for ulha rmdir and copyin commands

This commit is contained in:
2019-06-30 15:51:41 +02:00
parent 3d269303d9
commit f0a9e5f85d
2 changed files with 19 additions and 17 deletions

View File

@@ -23,18 +23,18 @@ from subprocess import check_output, CalledProcessError
class Archive(object): class Archive(object):
"""Archive handle. Provides interface to MC's extfs subsystem""" """Archive handle. Provides interface to MC's extfs subsystem"""
LINE_PAT = re.compile("^(?P<size>)\s" LINE_PAT = re.compile(b"^(?P<size>)\s"
"(?P<perms>)\s" b"(?P<perms>)\s"
"(?P<uid>)\s" b"(?P<uid>)\s"
"(?P<gid>)\s" b"(?P<gid>)\s"
"(?P<date>)\s+" b"(?P<date>)\s+"
"(?P<time>)\s" b"(?P<time>)\s"
"(?P<fpath>)") b"(?P<fpath>)")
ARCHIVER = "archiver_name" ARCHIVER = b"archiver_name"
CMDS = {"list": "l", CMDS = {"list": b"l",
"read": "r", "read": b"r",
"write": "w", "write": b"w",
"delete": "d"} "delete": b"d"}
ITEM = (b"%(perms)s 1 %(uid)-8s %(gid)-8s %(size)8s %(datetime)s " ITEM = (b"%(perms)s 1 %(uid)-8s %(gid)-8s %(size)8s %(datetime)s "
b"%(display_name)s\n") b"%(display_name)s\n")
@@ -53,7 +53,7 @@ class Archive(object):
leading space. This is workaround to this bug, which replaces leading leading space. This is workaround to this bug, which replaces leading
space with tilda.""" space with tilda."""
if name.startswith(b" "): if name.startswith(b" "):
new_name = "".join(["~", name[1:]]) new_name = b"".join([b"~", name[1:]])
return new_name return new_name
return name return name

10
ulha
View File

@@ -106,8 +106,9 @@ class ULha(Archive):
def rmdir(self, dst): def rmdir(self, dst):
"""Remove empty directory""" """Remove empty directory"""
dst = self._get_real_name(dst) dst = self._get_real_name(dst)
if not dst.endswith(os.path.sep):
dst += os.path.sep if not dst.endswith(bytes(os.path.sep, 'utf-8')):
dst += bytes(os.path.sep, 'utf-8')
if self._call_command('delete', dst=dst) is None: if self._call_command('delete', dst=dst) is None:
return 1 return 1
@@ -148,12 +149,13 @@ class ULha(Archive):
os.chdir(tmpdir) os.chdir(tmpdir)
if src: if src:
os.makedirs(os.path.dirname(dst)) os.makedirs(os.path.dirname(dst))
os.link(src, dst) shutil.copy2(src, dst)
else: else:
os.makedirs(dst) os.makedirs(dst)
try: try:
result = check_call([self.ARCHIVER, self.CMDS["write"], result = check_call([self.ARCHIVER.decode('utf-8'),
self.CMDS["write"].decode('utf-8'),
arch_abspath, dst]) arch_abspath, dst])
except CalledProcessError: except CalledProcessError:
return 1 return 1