Skip to content

Commit 6e4f79f

Browse files
authored
Add support for FreeBSD to ltfs_ordered_copy (#380)
1 parent 178a782 commit 6e4f79f

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

src/utils/ltfs_ordered_copy

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
# OO_Copyright_END
3535

3636
import sys
37+
import errno
3738
import platform
3839
import os.path
3940
import argparse
@@ -44,6 +45,11 @@ import threading
4445
from logging import getLogger, basicConfig, NOTSET, CRITICAL, ERROR, WARNING, INFO, DEBUG
4546
from collections import deque
4647

48+
def is_errno(num, names):
49+
if not num in errno.errorcode:
50+
return False
51+
return errno.errorcode[num] in names
52+
4753
class CopyItem:
4854
""""""
4955
def __init__(self, src, dst, vea_pre, cp_attr, cp_xattr, logger): #initialization
@@ -60,14 +66,14 @@ class CopyItem:
6066

6167
def eval(self): #access to the extended attributes present in some operating systems/filesystems by xattr
6268
try:
63-
self.vuuid = xattr.get(self.src, self.vea_pre + 'ltfs.volumeUUID')
69+
self.vuuid = xattr.getxattr(self.src, self.vea_pre + 'ltfs.volumeUUID')
6470
except Exception as e:
6571
self.vuuid = ''
6672
return (self.vuuid, self.part, self.start)
6773

6874
try:
69-
self.part = xattr.get(self.src, self.vea_pre + 'ltfs.partition')
70-
start_str = xattr.get(self.src, self.vea_pre + 'ltfs.startblock')
75+
self.part = xattr.getxattr(self.src, self.vea_pre + 'ltfs.partition')
76+
start_str = xattr.getxattr(self.src, self.vea_pre + 'ltfs.startblock')
7177
self.start = int(start_str)
7278
self.size = os.path.getsize(self.src)
7379
except Exception as e:
@@ -89,12 +95,12 @@ class CopyItem:
8995
if self.cp_xattr:
9096
# Capture EAs of the source file
9197
src_attributes = {}
92-
for key in xattr.list(self.src):
93-
src_attributes[key] = xattr.get(self.src, key)
98+
for key in xattr.listxattr(self.src):
99+
src_attributes[key] = xattr.getxattr(self.src, key)
94100
# Set EAs of the destination file
95101
(_, filename) = os.path.split(self.src)
96102
for key in src_attributes:
97-
xattr.set(self.dst, key, src_attributes[key])
103+
xattr.setxattr(self.dst, key, src_attributes[key])
98104
else: #Only copy data
99105
shutil.copy(self.src, self.dst)
100106
except Exception as e:
@@ -178,7 +184,7 @@ class CopyQueue:
178184
self.logger.log(NOTSET + 1, 'Making a directory {}'.format(d))
179185
os.mkdir(d)
180186
except OSError as e:
181-
if e.errno != 17: # Not EEXIST
187+
if e.errno != errno.EEXIST:
182188
self.logger.error(str(e) + "\n")
183189
exit(1)
184190

@@ -251,7 +257,7 @@ LTFS_SIG_VEA='ltfs.softwareProduct'
251257
plat = platform.system()
252258
if plat == 'Linux':
253259
VEA_PREFIX='user.'
254-
elif plat == 'Darwin':
260+
elif plat == 'Darwin' or plat == 'FreeBSD':
255261
VEA_PREFIX=''
256262
else:
257263
sys.stderr.write("unsupported platform '{0}'\n".format(plat))
@@ -362,18 +368,18 @@ if args.recursive == False and len(args.SOURCE) == 1:
362368
logger.log(NOTSET + 1, 'Checking destination is LTFS or not')
363369
direct_write_threads = 8
364370
try:
365-
sig = xattr.get(args.DEST, VEA_PREFIX + LTFS_SIG_VEA)
371+
sig = xattr.getxattr(args.DEST, VEA_PREFIX + LTFS_SIG_VEA)
366372

367373
if sig.startswith(b"LTFS"):
368374
logger.info("Destination {0} is LTFS".format(args.DEST))
369375
direct_write_threads = 1
370376
else:
371377
logger.info("Destination {0} is not LTFS\n".format(args.DEST))
372378
except IOError as e:
373-
if e.errno != 61 and e.errno != 93 and e.errno != 95: # Not ENODATA, ENOATTR, EOPNOTSUPP
379+
if not is_errno(e.errno, ['ENODATA', 'ENOATTR', 'ENOTSUP', 'EOPNOTSUPP']):
374380
logger.error('Check destination (I/O):' + str(e))
375381
exit(2)
376-
if e.errno == 95 and args.p:
382+
if is_errno(e.errno, ['ENOTSUP', 'EOPNOTSUPP']) and args.p:
377383
logger.warning("{0} does not support xattr. Cannot use -p. Attributes will not be preserved during copy.".format(args.DEST))
378384
args.p = False
379385
logger.warning("Destination {0} is not LTFS".format(args.DEST))

0 commit comments

Comments
 (0)