From: Darrick J. Wong Date: Tue, 9 Jun 2026 16:14:46 +0000 (-0700) Subject: xfs_protofile: make nondirectory arguments actually work X-Git-Tag: v7.1.0~11 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b3268fb3d822a7ef7d647284e0dfeaeb61713011;p=thirdparty%2Fxfsprogs-dev.git xfs_protofile: make nondirectory arguments actually work Codex points out that xfs_protofile fails if you pass it paths to non-directories. It's supposed to just copy them into the root directory, but we don't actually do that. Cc: # v6.13.0 Fixes: 6aace700b7b82d ("mkfs: add a utility to generate protofiles") Signed-off-by: "Darrick J. Wong" Reviewed-by: Christoph Hellwig --- diff --git a/mkfs/xfs_protofile.py.in b/mkfs/xfs_protofile.py.in index 40d06ddb4..00010fa7b 100644 --- a/mkfs/xfs_protofile.py.in +++ b/mkfs/xfs_protofile.py.in @@ -66,46 +66,56 @@ def max_fname_len(s1): '''Return the length of the longest string in s1.''' ret = 0 for s in s1: + ss = os.path.basename(s) if len(s) > ret: ret = len(s) return ret +def list_maybe_dir(path, depth): + try: + for fname in os.listdir(path): + yield os.path.join(path, fname) + except NotADirectoryError as e: + if depth == 1: + yield path + return + raise e + def walk_tree(path, depth): '''Walk the directory tree rooted by path.''' dirs = [] files = [] - for fname in os.listdir(path): - fullpath = os.path.join(path, fname) + for fullpath in list_maybe_dir(path, depth): sb = os.lstat(fullpath) if stat.S_ISDIR(sb.st_mode): - dirs.append(fname) + dirs.append(fullpath) continue elif stat.S_ISSOCK(sb.st_mode): continue else: - files.append(fname) + files.append(fullpath) - for fname in files: - if ' ' in fname: + for fullpath in files: + if ' ' in os.path.basename(fullpath): msg = _("Spaces not allowed in file names.") - raise ValueError(f'{fname}: {msg}') - for fname in dirs: - if ' ' in fname: + raise ValueError(f'{fullpath}: {msg}') + for fullpath in dirs: + if ' ' in os.path.basename(fullpath): msg = _("Spaces not allowed in subdirectory names.") - raise Exception(f'{fname}: {msg}') + raise Exception(f'{fullpath}: {msg}') fname_width = max_fname_len(files) - for fname in files: - fullpath = os.path.join(path, fname) + for fullpath in files: + fname = os.path.basename(fullpath) sb = os.lstat(fullpath) extra = stat_to_extra(sb, fullpath) print('%*s%-*s %s%s' % (depth, ' ', fname_width, fname, \ stat_to_str(sb), extra)) - for fname in dirs: - fullpath = os.path.join(path, fname) + for fullpath in dirs: + fname = os.path.basename(fullpath) sb = os.lstat(fullpath) extra = stat_to_extra(sb, fullpath) print('%*s%s %s' % (depth, ' ', fname, \ @@ -138,7 +148,7 @@ def main(): # Copy the first argument's stat to the rootdir statbuf = os.stat(args.paths[0]) if not stat.S_ISDIR(statbuf.st_mode): - raise NotADirectoryError(path) + raise NotADirectoryError(args.paths[0]) print(stat_to_str(statbuf)) # All files under each path go in the root dir, recursively