ECP-VeloC / AXL

Asynchronous Transfer Library
MIT License
2 stars 8 forks source link

copy uid, gid, permissions, and timestamps #68

Closed adammoody closed 4 years ago

adammoody commented 4 years ago

If AXL_COPY_METADATA=1, then copy file metadata, including uid, gid, permissions, and timestamps.

This only applies to pthread and sync so far, with the assumption that IBM BB and Cray Datawarp may already be copying this metadata. If not, it can be added to those.

Resolves: https://github.com/ECP-VeloC/AXL/issues/41

tonyhutter commented 4 years ago

Would you mind including this patch as well? It add flags to axl_cp to preserve timestamps/permissions.

diff --git a/test/axl_cp.c b/test/axl_cp.c
index 44d1516..62e0a11 100644
--- a/test/axl_cp.c
+++ b/test/axl_cp.c
@@ -6,9 +6,11 @@
 #include <errno.h>
 #include <sys/stat.h>
 #include <signal.h>
+#include <stdlib.h>
 #include "axl.h"

 int id = -1;
+char *old_env = NULL;

 /* Return 1 if path is a directory */
 static int
@@ -51,9 +53,11 @@ axl_xfer_str_to_xfer(const char *xfer_str)
 static void
 usage(void)
 {
-    printf("Usage: axl_cp [-r|-R] [-X xfer_type] SOURCE DEST\n");
-    printf("       axl_cp [-r|-R] [-X xfer_type] SOURCE... DIRECTORY\n");
+    printf("Usage: axl_cp [-ap] [-r|-R] [-X xfer_type] SOURCE DEST\n");
+    printf("       axl_cp [-ap] [-r|-R] [-X xfer_type] SOURCE... DIRECTORY\n");
     printf("\n");
+    printf("-a:             Archive mode.  Preserve permissions + times + recursive.  Implies -pr\n");
+    printf("-p:             Preserve permissions + times.\n");
     printf("-r|-R:          Copy directories recursively\n");
     printf("-X xfer_type:   AXL transfer type:  default native pthread sync dw bbapi cppr\n");
     printf("\n");
@@ -86,6 +90,9 @@ void sig_func(int signum)
         exit(rc);
     }

+    if (old_env)
+        setenv("AXL_COPY_METADATA", old_env, 1);
+
     exit(AXL_SUCCESS);
 }

@@ -107,9 +114,17 @@ main(int argc, char **argv) {
     action.sa_handler = sig_func;
     sigaction(SIGTERM, &action, NULL);
     char *state_file = NULL;
+    int preserve = 0;

-    while ((opt = getopt(argc, argv, "rRSX:")) != -1) {
+    while ((opt = getopt(argc, argv, "aprRSX:")) != -1) {
         switch (opt) {
+            case 'p':
+                preserve = 1;
+                break;
+            case 'a':
+                preserve = 1;
+                recursive = 1;
+                break;
             case 'X':
                 xfer_str = optarg;
                 break;
@@ -125,6 +140,10 @@ main(int argc, char **argv) {
                 exit(1);
         }
     }
+
+    if (preserve)
+       old_env = getenv("AXL_COPY_METADATA");
+
     args_left = argc - optind;

     /* Did they specify source(s) and destination? */
@@ -163,6 +182,9 @@ main(int argc, char **argv) {
         xfer = AXL_XFER_SYNC;
     }

+    if (preserve)
+        setenv("AXL_COPY_METADATA", "1", 1);
+
     rc = AXL_Init(state_file);
     if (rc != AXL_SUCCESS) {
         printf("AXL_Init() failed (error %d)\n", rc);
@@ -212,5 +234,8 @@ main(int argc, char **argv) {
         return rc;
     }

+    if (old_env)
+        setenv("AXL_COPY_METADATA", old_env, 1);
+
     return AXL_SUCCESS;
 }
adammoody commented 4 years ago

@tonyhutter , yeah that's good. Thanks. Go ahead and directly push that commit to the existing metadata branch.

tonyhutter commented 4 years ago

Thanks, pushed.

adammoody commented 4 years ago

Thanks for adding your patch, @tonyhutter !