[PATCH]: Create directories on remote host.

Jesus Climent <[email protected]> Mon, 31 Jul 2006 13:17:22 +0200
Newsgroups gmane.comp.web.sitecopy
Message-ID <[email protected]>
Hi *.

A friend of mine (Moises Martinez) managed to integrate a patch to create a
tree of directories in the remote server of "-x" if provided as an option.

The patch is available as an attachment.

Cheers,
-- 
Jesus Climent                  info:www.pumuki.org dj:triplestereo.com
Unix SysAdm|Linux User #66350|Debian Developer|2.6.17|Helsinki Finland
GPG: 1024D/86946D69 BB64 2339 1CAA 7064 E429  7E18 66FC 1D7F 8694 6D69

Pray that there's intelligent life somewhere out in space / 'Cause there's
bugger all down here on earth!
		--Man (Monty Python's The Meaning of Life)

_______________________________________________
sitecopy maillist  -  [email protected]
http://dav.lyra.org/mailman/listinfo/sitecopy
sitecopy-0.16.1-remote-2.patch (text/plain, 4.5 KB)
diff -urN sitecopy-0.16.1/src/console_fe.c sitecopy-0.16.1-moimart/src/console_fe.c
--- sitecopy-0.16.1/src/console_fe.c	2006-07-28 17:36:50.529072000 +0300
+++ sitecopy-0.16.1-moimart/src/console_fe.c	2006-07-28 19:20:37.194214250 +0300
@@ -160,7 +160,8 @@
     show_progress, /* Do they want the %-complete messages */
     prompting, /* Did they say --prompting? */
     keepgoing, /* Did they say --keep-going? */
-    dry_run;   /* Did they say --dry-run? */
+    dry_run,   /* Did they say --dry-run? */
+    createremoteroot=false; /* Did they say --create-remote? */
 
 /* Functions prototypes */
 static void init(int, char **);
@@ -228,9 +229,9 @@
 	exit(-1);
     }
 
-    for (current=all_sites; current!=NULL; current=current->next) {
+    for (current=all_sites; current!=NULL; current=current->next) {	
 	
-	if (current->use_this || allsites) {
+	if (current->use_this || allsites) {	
 	    if (!listflat && quiet == 0) {
 		/* Display the banner line */
 		const char *str_action = _(actions[action].doing);
@@ -462,7 +463,7 @@
 #ifdef NE_DEBUGGING
 	"d:g:"
 #endif
-	"acefhiklonp:qr:suvVyZ"; /* available: bgjmntwx */
+	"acefhikxlonp:qr:suvVyZ"; /* available: bgjmntwx */
     const static struct option longopts[] = {
 	/* Operation modes */
 	{ "update", no_argument, NULL, 'u' },
@@ -489,6 +490,7 @@
 	{ "logfile", required_argument, NULL, 'g' },
 #endif
 	{ "prompting", no_argument, NULL, 'y' },
+	{ "create-remote", no_argument, NULL, 'x' },
 	{ "allsites", no_argument, NULL, 'a' },
 	{ "version", no_argument, NULL, 'V' },
 	{ 0, 0, 0, 0 }
@@ -583,6 +585,9 @@
 	    }
 	} break;
 #endif
+	case 'x':
+	    createremoteroot = true;
+	    break;
 	case 'y':
 	    prompting = true;
 	    break;
@@ -1287,7 +1292,8 @@
     int ret = 0, verify_removed;
 
     /* Set the options */
-    site->keep_going = keepgoing;
+    site->keep_going         = keepgoing;
+    site->create_remote_root = createremoteroot;
 
     switch (act) {
     case action_update:
@@ -1431,6 +1437,7 @@
 "  -p, --storepath=PATH  Use alternate site storage directory\n"
 "  -y, --prompting       Request confirmation before making each update\n"
 "  -a, --allsites        Perform the operation on ALL defined sites\n"
+"  -x, --create-remote   Create root for remote site\n"
 "  -k, --keep-going      Carry on an update regardless of errors\n"
 "  -o, --show-progress   Display total percentage file transfer complete\n"
 "  -q, --quiet           Be quiet while performing the operation\n"
diff -urN sitecopy-0.16.1/src/sites.c sitecopy-0.16.1-moimart/src/sites.c
--- sitecopy-0.16.1/src/sites.c	2005-08-07 23:24:29.000000000 +0300
+++ sitecopy-0.16.1-moimart/src/sites.c	2006-07-31 12:25:06.398608000 +0300
@@ -312,11 +312,52 @@
     free(full_remote);
 }
 
+static int create_remote_root_dirs(struct site *site, void *session)
+{
+    char *buffer;
+    int i,j=0,ret=1,flag=1;
+
+    buffer = (char *) calloc(strlen(site->remote_root)+1,sizeof(char));
+
+    buffer[j++] = '/';
+
+    for( i=1 ; site->remote_root[i] != '\0' ; i++ )
+    {
+      if (site->remote_root[i] == '/')
+        flag = 0;
+      
+      if (flag)
+        buffer[j++] = site->remote_root[i];
+      else
+	if (j > 0)
+        {
+	  buffer[j] = '\0';
+	  ret = CALL(dir_create)(session, buffer);
+
+	  if (ret != SITE_OK)
+ 	    ret = 0;
+
+	  buffer[j++] = '/';
+	  flag=1;
+	} 
+    }
+		   
+    return ret;
+}	
+
 /* Create new directories and change permissions on existing directories. */
 static int update_create_directories(struct site *site, void *session)
 {
     struct site_file *current;
-    int ret = 0;
+    int ret = 0, ret_root_dir;
+
+    if (site->create_remote_root) /* We create remote init struct before updating the whole stuff */
+    {
+      ret_root_dir = create_remote_root_dirs(site,session);
+      
+      if (!ret_root_dir)
+        fe_warning (_("I couldn't create some dir. already exists?"),NULL,NULL);	
+    }
 
     for_each_file(current, site) {
 	if ((current->type == file_dir) 
diff -urN sitecopy-0.16.1/src/sites.h sitecopy-0.16.1-moimart/src/sites.h
--- sitecopy-0.16.1/src/sites.h	2005-01-24 23:52:53.000000000 +0200
+++ sitecopy-0.16.1-moimart/src/sites.h	2006-07-28 17:26:39.126861750 +0300
@@ -379,6 +379,8 @@
     char *rsh_cmd;
     char *rcp_cmd;
 
+    unsigned int create_remote_root:1; /* to create remote root in case it doesn't exist */
+
     unsigned int nodelete:1; /* whether to delete any files remotely */
     unsigned int checkmoved:1; /* whether to check for moved files */
     unsigned int checkrenames:1; /* whether to check for renamed files */