diff mbox series

[v2,1/2] Fixed issue with restore of xattrs not working on directories

Message ID 20230202043345.14010-1-jakob@dsi.uni-stuttgart.de (mailing list archive)
State New, archived
Headers show
Series [v2,1/2] Fixed issue with restore of xattrs not working on directories | expand

Commit Message

Holger Jakob Feb. 2, 2023, 4:33 a.m. UTC
Restore was only setting xattrs on files but ignored directories.
The patch adds a missing set_file_xattrs

Signed-off-by: Holger Jakob <jakob@dsi.uni-stuttgart.de>
---
 cmds/restore.c | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

Comments

David Sterba March 16, 2023, 3:32 p.m. UTC | #1
On Wed, Feb 01, 2023 at 08:33:44PM -0800, Holger Jakob wrote:
> Restore was only setting xattrs on files but ignored directories.
> The patch adds a missing set_file_xattrs
> 
> Signed-off-by: Holger Jakob <jakob@dsi.uni-stuttgart.de>

Added to devel with some minor updates, thanks.
diff mbox series

Patch

diff --git a/cmds/restore.c b/cmds/restore.c
index 19df6be2..18edc8ca 100644
--- a/cmds/restore.c
+++ b/cmds/restore.c
@@ -1117,11 +1117,11 @@  next:
 		path.slots[0]++;
 	}
 
-	if (restore_metadata) {
+	if (restore_metadata || get_xattrs) {
 		snprintf(path_name, PATH_MAX, "%s%s", output_rootdir, in_dir);
 		fd = open(path_name, O_RDONLY);
 		if (fd < 0) {
-			error("failed to access '%s' to restore metadata: %m",
+			error("failed to access '%s' to restore metadata/xattrs: %m",
 					path_name);
 			if (!ignore_errors) {
 				ret = -1;
@@ -1132,7 +1132,23 @@  next:
 			 * Set owner/mode/time on the directory as well
 			 */
 			key->type = BTRFS_INODE_ITEM_KEY;
-			ret = copy_metadata(root, fd, key);
+			if (restore_metadata) {
+				ret = copy_metadata(root, fd, key);
+				if (ret && !ignore_errors) {
+					close(fd);
+					goto out;
+				}
+			}
+
+			/*
+			 * Also set xattrs on the directory
+			 */
+			if (get_xattrs) {
+				ret = set_file_xattrs(root, key->objectid, fd, path_name);
+				if (ret) {
+					error("failed to set xattrs: %m");
+				}
+			}
 			close(fd);
 			if (ret && !ignore_errors)
 				goto out;