Skip to content

Commit adb3722

Browse files
ltfs_ordered_copy now sorts files in the correct order before copying (#512)
1 parent 2c0cd5a commit adb3722

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/utils/ltfs_ordered_copy

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,12 @@ class CopyQueue:
116116
""""""
117117
HalfMegaByte = 512 * 1024
118118

119-
def __init__(self, logger): #initialization
119+
def __init__(self, logger, sort_files = False): #initialization
120120
self.direct = deque([])
121121
self.tape_dict = {}
122122
self.items = 0
123123
self.logger = logger
124+
self.sort_files = sort_files
124125

125126
def add_copy_item(self, c):
126127
(u, p, s) = c.eval()
@@ -171,9 +172,9 @@ class CopyQueue:
171172
dst = dest + "/" + t
172173
dst = os.path.normpath(dst)
173174

174-
for d in dirs:
175+
for d in sorted(dirs) if self.sort_files else dirs:
175176
walk_dirs.append(os.path.join(dst, d))
176-
for f in files:
177+
for f in sorted(files) if self.sort_files else files:
177178
self.logger.log(NOTSET + 1, 'Creating a copy item for file {}'.format(f))
178179
c = CopyItem(os.path.join(root, f), os.path.join(dst, f), VEA_PREFIX,
179180
cp_attr, cp_xattr, logger)
@@ -284,6 +285,7 @@ parser.add_argument('-a','--all', help='achieve files recursively and preserve a
284285
parser.add_argument('-v', help='Verbose output. Set VERBOSE level 5', action='store_true')
285286
parser.add_argument('--verbose', help='Configure verbosity of logger. VERBOSE shall be 0-6. default is 4', default = str(logger_info))
286287
parser.add_argument('-q','--quiet', help='No message output', action='store_true')
288+
parser.add_argument('--sort-files', help='Sort the file list before copying', action='store_true')
287289

288290
args=parser.parse_args()
289291

@@ -395,7 +397,7 @@ if len(args.SOURCE) == 0:
395397
logger.log(NOTSET + 1, 'Source: {}'.format(args.SOURCE))
396398

397399
# Create the list of copy item
398-
copyq = CopyQueue(logger)
400+
copyq = CopyQueue(logger, args.sort_files)
399401
for s in args.SOURCE:
400402
dst = args.DEST
401403
if os.path.isfile(s):

0 commit comments

Comments
 (0)