shadow_copy2: factor shadow_copy2_posix_gmt_string() out of shadow_copy2_insert_string()
authorMichael Adam <obnox@samba.org>
Thu, 30 May 2013 21:51:02 +0000 (23:51 +0200)
committerKarolin Seeger <kseeger@samba.org>
Mon, 13 Jan 2014 09:17:21 +0000 (10:17 +0100)
for re-use..

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
(cherry picked from commit 4cc5140bbe207f08d9b4fb0d119e74cc839e55dd)

source3/modules/vfs_shadow_copy2.c

index 5db0811e06d9cbddab60d9cb255d5a062e97eeb1..1347b931b48339aa2a580a88c82b37ef6ef48f0a 100644 (file)
@@ -158,60 +158,86 @@ static bool shadow_copy2_find_slashes(TALLOC_CTX *mem_ctx, const char *str,
 }
 
 /**
- * Given a timstamp, build the string to insert into a path
- * as a path component for creating the local path to the
- * snapshot at the given timestamp of the input path.
- *
- * In the case of a parallel snapdir (specified with an
- * absolute path), this is the inital portion of the
- * local path of any snapshot file. The complete path is
- * obtained by appending the portion of the file's path
- * below the share root's mountpoint.
+ * Given a timstamp, build the posix level GTM-tag string
+ * based on the configurable format.
  */
-static char *shadow_copy2_insert_string(TALLOC_CTX *mem_ctx,
-                                       struct vfs_handle_struct *handle,
-                                       time_t snapshot)
+static size_t shadow_copy2_posix_gmt_string(struct vfs_handle_struct *handle,
+                                           time_t snapshot,
+                                           char *snaptime_string,
+                                           size_t len)
 {
        struct tm snap_tm;
-       fstring snaptime_string;
        size_t snaptime_len;
        struct shadow_copy2_config *config;
-       char *result = NULL;
 
        SMB_VFS_HANDLE_GET_DATA(handle, config, struct shadow_copy2_config,
-                               return NULL);
+                               return 0);
 
        if (config->use_sscanf) {
                snaptime_len = snprintf(snaptime_string,
-                                       sizeof(snaptime_string),
+                                       len,
                                        config->gmt_format,
                                        (unsigned long)snapshot);
                if (snaptime_len <= 0) {
                        DEBUG(10, ("snprintf failed\n"));
-                       return NULL;
+                       return snaptime_len;
                }
        } else {
                if (config->use_localtime) {
                        if (localtime_r(&snapshot, &snap_tm) == 0) {
                                DEBUG(10, ("gmtime_r failed\n"));
-                               return NULL;
+                               return -1;
                        }
                } else {
                        if (gmtime_r(&snapshot, &snap_tm) == 0) {
                                DEBUG(10, ("gmtime_r failed\n"));
-                               return NULL;
+                               return -1;
                        }
                }
                snaptime_len = strftime(snaptime_string,
-                                       sizeof(snaptime_string),
+                                       len,
                                        config->gmt_format,
                                        &snap_tm);
                if (snaptime_len == 0) {
                        DEBUG(10, ("strftime failed\n"));
-                       return NULL;
+                       return 0;
                }
        }
 
+       return snaptime_len;
+}
+
+/**
+ * Given a timstamp, build the string to insert into a path
+ * as a path component for creating the local path to the
+ * snapshot at the given timestamp of the input path.
+ *
+ * In the case of a parallel snapdir (specified with an
+ * absolute path), this is the inital portion of the
+ * local path of any snapshot file. The complete path is
+ * obtained by appending the portion of the file's path
+ * below the share root's mountpoint.
+ */
+static char *shadow_copy2_insert_string(TALLOC_CTX *mem_ctx,
+                                       struct vfs_handle_struct *handle,
+                                       time_t snapshot)
+{
+       fstring snaptime_string;
+       size_t snaptime_len = 0;
+       char *result = NULL;
+       struct shadow_copy2_config *config;
+
+       SMB_VFS_HANDLE_GET_DATA(handle, config, struct shadow_copy2_config,
+                               return NULL);
+
+       snaptime_len = shadow_copy2_posix_gmt_string(handle,
+                                                    snapshot,
+                                                    snaptime_string,
+                                                    sizeof(snaptime_string));
+       if (snaptime_len <= 0) {
+               return NULL;
+       }
+
        if (config->snapdir_absolute) {
                result = talloc_asprintf(mem_ctx, "%s/%s",
                                         config->snapdir, snaptime_string);