home *** CD-ROM | disk | FTP | other *** search
- /* (C) Tim Graves 20th April 1994
- This code is supplied AS IS. no warrantee either expressed or implied
- is provided. This code may be freeley modified and modified as long as my
- origional authorship is acknowledged.
-
- Tim Graves
- Sun Microsystems
-
- */
- /* this module performs a backup of the files on the psion under path and stores it in backup, no input filtering is done (VAR_FILEFILT) is removed)*/
-
- #include <stdio.h>
- #include <ctype.h>
- #include <string.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include "psion.h"
- #include "psbackup.h"
- static char vsn[] = "@(#) psbackup.c 3.6@(#)" ;
- struct backupentry * backhead ;
- int debugbackup = FALSE ;
- int incremental = FALSE ;
- extern int debugcall ;
- int filecount, dircount ;
- psrlist(path, fd)
- char * path ;
- FILE * fd ;
- {
- if (debugcall >= BACKUPCALLDEBUG)
- fprintf(stderr, "CALL: psrlist (path = %s)\n", path) ;
- if (findvar(VAR_VERBOSE) != NULL)
- printf("Generating a recursive listing of %s\n",path) ;
- /* force the incremental flag to be false as this is a listing */
- incremental = FALSE ;
- lowerpath(path) ;
- initbackuplist(path) ;
- backuplist(backhead,FALSE,"", "") ;
- printbackuplist(backhead, fd) ;
- closebackuplist(backhead) ;
- }
-
- psbackup(path,backupdir, incr)
- char * path,* backupdir ;
- {
- int filefilterwasset;
- int ch ;
- time_t timestart, timeend ;
- if (debugcall >= BACKUPCALLDEBUG)
- fprintf(stderr, "CALL: psbackup (path = %s, backupdir = %s, incr = %d)\n", path, backupdir, incr) ;
-
- /* if backupnocheck is set dont ask the user to close all the files
- This is potentialy dangerous as suncom can't get a file if it is
- open */
- if (findvar(VAR_BACKUPNOCHECK) == NULL)
- {
- /* ask the user to ensure that all open files on the psion are closed */
- printf("BACKUP: Please ensure that all files on the psion are closed\n");
- printf("BACKUP: Press return to continue\n");
- ch = getchar();
- }
- /* is this incremental ? */
- incremental = incr ;
- /* reset the file/dir counts */
- filecount = 0 ;
- dircount = 0 ;
- /* get the start time */
- timestart = time(NULL) ;
- if (findvar(VAR_VERBOSE) != NULL)
- {
- printf("BACKUP: Starting %sbackup of %s to %s\n", incremental ? "incremental " : "", path,backupdir);
- printf("BACKUP: %s\n", ctime(×tart)) ;
- printf("BACKUP: Stage 1, Building file list\n");
- }
- lowerpath(path) ;
- initbackuplist(path) ;
- /* was VAR_FILEFILT set ? if so unsetit */
- if (findvar(VAR_FILEFILT) != NULL)
- {
- filefilterwasset=TRUE ;
- delvar(VAR_FILEFILT) ;
- }
- /* build a list of files to backup using the excludlist*/
- backuplist(backhead,TRUE, backupdir, path) ;
- /* do the backup */
- if (findvar(VAR_VERBOSE) != NULL)
- printf("BACKUP: Stage 2, Getting files\n");
- dobackup(backupdir,backhead, path) ;
- /* free the accumulated data structures */
- closebackuplist(backhead) ;
- /* reset the VAR_FILEFILT if it was set */
- if (filefilterwasset)
- addvar(VAR_FILEFILT,"") ;
- timeend = time(NULL) ;
- if (findvar(VAR_VERBOSE) != NULL)
- {
- printf("BACKUP: %s of %s to %s complete\n", incremental ? "Incremental backup" : "Backup", path, backupdir) ;
- printf("BACKUP: %s\n", ctime(&timeend)) ;
- printf("BACKUP: %d directories, %d files\n", dircount, filecount) ;
- printf("BACKUP: Time taken %d seconds\n", (int) timeend - timestart) ;
- }
-
- }
- backuplist(currnode,exclude, backupdir, psionpath)
- struct backupentry *currnode ;
- int exclude ;
- char * backupdir, *psionpath ;
- {
- int i ;
- char tmp[100], nodepath[1024];
- FILE * fd ;
- struct backupentry *child ;
- int nodepathlen ;
- if (debugcall >= BACKUPCALLDEBUG)
- fprintf(stderr, "CALL: backuplist (currnode->pname = %s, exclude = %d, backupdir = %s, psionpath= %s)\n", currnode->pname, exclude, backupdir, psionpath) ;
- /* are we using the excludelist ? if so is thie item on it ? */
- if (exclude)
- {
- if (currnode->exclude = findexclude(currnode->pname))
- return ;
- }
- /* if the current node is a file set the flg and and check
- that the file mod has not changed, if so exclude it */
- if ((currnode->nodetype=backuppathtype(currnode->pname)) == BACKUPNODEFILE)
- {
- if (incremental)
- currnode->exclude = backupmodified(currnode->pname,backupdir, psionpath) ;
- return ;
- }
- /* the current node is a directory, Lets work on it */
- /* build up the list command */
- strcpy(tmp, "list ");
- strcat(tmp,currnode->pname) ;
- /* remember we need a \ to make the search work */
- strcat(tmp,"\\");
- strcat(tmp," ");
- strcat(tmp,BACKUPLISTNAME) ;
- /* list the current node use cmdintr to do the work ! */
- cmdintr(tmp) ;
- /* we now have a list in BACKUPLISTNAME of all the items in this node lets get them !*/
- if ((fd = fopen(BACKUPLISTNAME,"r")) == NULL)
- {
- printf("ERROR: Error in opening backup temporary file quiting\n") ;
- psdc() ;
- }
- while (fgets(nodepath,120,fd) != NULL)
- /* for each item in the current node */
- {
- /* if the last char is newline, removeit, cmdintr
- doesnot like it */
- nodepathlen = strlen(nodepath) ;
- if (nodepath[nodepathlen -1] == '\n')
- nodepath[nodepathlen -1] = 0 ;
- if (debugbackup)
- printf("Now working on %s\n", nodepath) ;
- /* create a new node and install its name */
- lowerpath(nodepath) ;
- backupaddchild(currnode,nodepath) ;
- }
- fclose(fd) ;
- /* remove the tmp file so others running the program won't
- have a problem */
- if (unlink (BACKUPLISTNAME))
- printf("ERROR: Error in removing backup temporary file\n") ;
- /* get ready to scan the children in the current node */
- child = currnode->children ;
- /* for each item in the current node */
- while(child != NULL)
- {
- /* recursively call backuplist to work on the new item */
- backuplist(child,exclude, backupdir, psionpath) ;
- child = child->next ;
- }
- }
- backuppathtype(path)
- char * path ;
- {
- int atts ;
- pssetpath(path) ;
- atts = psgetatts() ;
- if (atts & PSFILEDIR)
- return(BACKUPNODEDIR) ;
- else
- return(BACKUPNODEFILE );
- }
- struct backupentry * backupnode(path)
- char * path ;
- {
- int i ;
- struct backupentry * ret ;
- if (debugcall >= BACKUPCALLDEBUG)
- fprintf(stderr, "CALL: backupentry (path = %s)\n", path) ;
- /* create the ctructure */
- ret = (struct backupentry *) calloc (1,sizeof(struct backupentry)) ;
- /* fill in the name */
- ret->pname = (char *) calloc(1,strlen(path) +1) ;
- strcpy(ret->pname,path) ;
- /* ensure that we done know what type of node this is */
- ret->nodetype = BACKUPNODEUNKNOWN ;
- /* initialy thie node is not excluded */
- ret->exclude = FALSE ;
- /* initialy this node has no children */
- ret->children = NULL ;
- /* initialy there is no next pointer */
- ret->next = NULL ;
- if (debugbackup)
- printf("BACKUP: adding %s\n", path) ;
- return (ret) ;
- }
-
- initbackuplist(path)
- char * path ;
- {
- /* create the first entry */
- if (debugcall >= BACKUPCALLDEBUG)
- fprintf(stderr, "CALL: initbackuplist ()\n") ;
- backhead = backupnode(path) ;
- }
- backupaddchild(currnode,nodepath)
- char * nodepath ;
- struct backupentry * currnode ;
- {
- struct backupentry * tmp ;
- if (debugcall >= BACKUPCALLDEBUG)
- fprintf(stderr, "CALL: backupaddchild (currnode->pname, nodepath = %s)\n", currnode->pname, nodepath) ;
- /* create the node - note -> next is initialised to NULL */
- tmp = backupnode(nodepath) ;
- /* insert the new node into the head of the list of children in the current node */
- tmp->next = currnode->children ;
- currnode->children = tmp ;
- }
- closebackuplist (currnode)
- struct backupentry * currnode ;
- {
- struct backupentry * child, *nextchild ;
- if (debugcall >= BACKUPCALLDEBUG)
- fprintf(stderr, "CALL: closebackuplist (currnode->pname = %s)\n", currnode->pname) ;
- /* for each entry in the current node kill the children */
- child = currnode->children ;
- while(child != NULL)
- {
- /* save a pointer to the next child otherwise we will be referencing through freed data */
- nextchild = child -> next ;
- closebackuplist(child) ;
- child = nextchild ;
- }
- /* no children left, free ourselves */
- free(currnode->pname) ;
- free (currnode) ;
- }
- printbackuplist(currnode, fd)
- struct backupentry * currnode ;
- FILE * fd ;
- {
- struct backupentry *child ;
- int i ;
- if (debugcall >= BACKUPCALLDEBUG)
- fprintf(stderr, "CALL: printbackuplist (currnode->pname = %s)\n", currnode->pname) ;
-
- /* print the curent node name and then do eack of the children */
- if ( fd == NULL)
- printf("%s\n",currnode->pname) ;
- else
- fprintf(fd, "%s\n", currnode->pname) ;
-
- /* for each entry in the current print the children */
- child = currnode->children ;
- while (child != NULL)
- {
- printbackuplist(child, fd) ;
- child = child->next ;
- }
- /* no children left return */
- return ;
- }
- dobackup(path,currnode, psionpath)
- char * path, *psionpath ;
- struct backupentry * currnode ;
- {
- int i ;
- char * tmp ;
- char resp [10] ;
- char targetpath [1024] ;
- char cmd[2048] ;
- struct backupentry * child ;
- if (debugcall >= BACKUPCALLDEBUG)
- fprintf(stderr, "CALL: dobackup (path = %s, currnode->pname = %s, psionpath= %s)\n",path, currnode->pname, psionpath) ;
- /* check that the current node is not excluded */
- if (currnode->exclude)
- return ;
-
- /* if the current entry is a file get it and return */
- if (currnode->nodetype == BACKUPNODEFILE)
- {
- /* get it */
- if (debugbackup)
- printf("BACKUP: Getting %s\n", currnode->pname) ;
- /* build up the command to do the get */
- strcpy (cmd, "get ") ;
- strcat (cmd, currnode->pname) ;
- /* its now safe to call the path munger as we have a copy of the
- path in cmd */
- backupbuildpath(currnode->pname, path, targetpath, psionpath) ;
- strcat(cmd, " ") ;
- strcat(cmd,targetpath) ;
- if (debugbackup)
- printf("BACKUP: doing %s\n",cmd) ;
- /* if VAR_BACKUPNODO just print the command */
- if (findvar(VAR_BACKUPNODO) != NULL)
- {
- printf("BACKUP: Would have done \"%s\"\n", cmd);
- }
- else
- {
- /* if VAR_BACKUPASK check to see if we went to do this one */
- if (findvar(VAR_BACKUPASK) != NULL)
- {
- printf("BACKUP: Do you want to backup file %s ? (y/n) ", currnode->pname) ;
- fgets(resp, sizeof(resp), stdin) ;
- if ((resp[0] == 'y') || (resp[0] == 'Y'))
- {
- cmdintr(cmd) ;
- }
- }
- else
- {
- cmdintr(cmd) ;
- }
- }
- /* increment the filecount */
- filecount ++ ;
- return ;
- }
- else
- {
- /* the current entry is a directory, make it in the filesystem and then look at all its children */
- /* make the directory */
- if (debugbackup)
- printf("BACKUP: Making dir %s\n",currnode->pname) ;
- /* build up the command to do the mkdir */
- strcpy (cmd, "mkdir -p ") ;
- backupbuildpath(currnode->pname, path, targetpath, psionpath) ;
- strcat(cmd,targetpath) ;
- if (debugbackup)
- printf("BACKUP: doing system(%s)\n", cmd) ;
- /* if VAR_BACKUPNODO just print the command */
- if (findvar(VAR_BACKUPNODO) != NULL)
- {
- printf("BACKUP: Would have done \"%s\"\n", cmd);
- }
- else
- {
- /* if VAR_BACKUPASK check to see if we went to do this one */
- if (findvar(VAR_BACKUPASK) != NULL)
- {
- printf("BACKUP: Do you want to backup directory %s ? (y/n) ", currnode->pname) ;
- fgets(resp, sizeof(resp), stdin) ;
- if ((resp[0] == 'y') || (resp[0] == 'Y'))
- {
- system(cmd) ;
- }
- else
- {
- printf("BACKUP: Warning, as you are not backing up directory %s none of its children will be backed up\n", currnode->pname) ;
- return ;
- }
- }
- else
- {
- system(cmd) ;
- }
- }
- /* for each entry in the current get the children */
- child = currnode->children ;
- while(child != NULL)
- {
- dobackup(path,child, psionpath) ;
- child = child -> next ;
- }
- /* no children left increment the dircount and return */
- dircount ++ ;
- return ;
- }
- }
-
- backupbuildpath(path, root, target, purge)
- char * path, *root, *target, *purge;
- {
- int i ;
- char tmp[1024],* tmpptr ;
- if(debugcall >= BACKUPCALLDEBUG)
- fprintf(stderr, "CALL backupbuildpath (path = %s, root = %s, target = OMITTED, purge = %s)\n", path, root, purge) ;
- /* path is the path to munge (remove purge change all \ to /) */
- /* also change all $ to S the drive is assumed to be the purge entry*/
- /* root is the unix directory at the top of this tree */
- /* target is the place to put the resultant string */
-
- strcpy(tmp, path) ;
- tmpptr = tmp ;
- /* whilst the two are the same and neither are the end of string move
- allong the two removing characters from the front of the array */
- while ((purge[0] == tmpptr[0]) && (purge[0] != '\0') && (tmpptr[0] != '\0'))
- {
- purge ++ ;
- tmpptr ++ ;
- }
-
- /* change the \ to / and $ to S */
- for (i = 0 ; i < (int) strlen(tmpptr) ; i ++ )
- {
- if (tmpptr[i] == '$')
- {
- tmpptr[i] = 'S' ;
- }
- else if (tmpptr[i] == '\\')
- {
- tmpptr[i] = '/' ;
- }
- }
- /* build the output name */
- strcpy(target, root) ;
- strcat(target,tmpptr) ;
- if(debugcall >= BACKUPCALLDEBUG)
- fprintf(stderr, "EXIT: backupbuildpath (target = %s)\n", target) ;
- }
- long psgetmodtime() ;
- backupmodified(psname, backupdir, psionpath)
- char * psname, *backupdir, *psionpath;
- {
- char sunpath [1024] ;
- char tmp [100] ;
- long pstime , suntime ;
- struct stat sunstat ;
- int ret ;
- if (debugcall >= BACKUPCALLDEBUG)
- fprintf(stderr, "CALL: backupmodified (psname = %s, backupdir = %s, psionpath= %s)\n",psname, backupdir, psionpath) ;
-
- /* has the file on the psion been changes more recently
- than the backup ? */
-
- pssetpath(psname) ;
- pstime = psgetmodtime() ;
-
- /* create a temporary copy of the psname so we can work on it */
- strcpy(tmp, psname) ;
- /* get the sunname for this */
- backupbuildpath(tmp, backupdir, sunpath, psionpath) ;
-
- /* get the mod time of the sun file if it exists */
- ret = stat(sunpath, &sunstat) ;
- if (ret != 0)
- return(FALSE) ;
-
- #ifndef SVR4
- if (debugbackup)
- printf("ret = %d suntime = %ld pstime = %ld\n", ret, sunstat.st_mtime, pstime) ;
- if ((pstime + CLOCKDIFF) < sunstat.st_mtime)
- return(TRUE) ;
- else
- return(FALSE) ;
- #else
- if (debugbackup)
- printf("ret = %d suntime = %ld pstime = %ld\n", ret, sunstat.st_mtim.tv_sec, pstime) ;
-
- if ((pstime + CLOCKDIFF) < sunstat.st_mtim.tv_sec)
- return(TRUE) ;
- else
- return(FALSE) ;
- #endif
- }
-
- /* the restore code lives here */
- psrestore(psionpath,restoredir, incr)
- char * psionpath,* restoredir ;
- {
- int filefilterwasset;
- int ch ;
- time_t timestart, timeend ;
- if (debugcall >= BACKUPCALLDEBUG)
- fprintf(stderr, "CALL: psrestore (psionpath = %s, restoredir = %s, incr = %d)\n", psionpath, restoredir, incr) ;
-
- /* if backupnocheck is set dont ask the user to close all the files
- This is potentialy dangerous as suncom can't put a file if it is
- open */
- if (findvar(VAR_BACKUPNOCHECK) == NULL)
- {
- /* ask the user to ensure that all open files on the psion are closed */
- printf("RESTORE: Please ensure that all files on the psion are closed\n");
- printf("RESTORE: Press return to continue\n");
- ch = getchar();
- }
- /* is this incremental ? */
- incremental = incr ;
- /* reset the file/dir counts */
- filecount = 0 ;
- dircount = 0 ;
- /* get the start time */
- timestart = time(NULL) ;
- if (findvar(VAR_VERBOSE) != NULL)
- {
- printf("RESTORE: Starting %srestore of %s to %s\n", incremental ? "incremental " : "", restoredir, psionpath);
- printf("RESTORE: %s\n", ctime(×tart)) ;
- printf("RESTORE: Stage 1, Building file list\n");
- }
- /* NOTE we are using the same data structures for backup as restore */
- initbackuplist(restoredir) ;
- /* was VAR_FILEFILT set ? if so unsetit */
- if (findvar(VAR_FILEFILT) != NULL)
- {
- filefilterwasset=TRUE ;
- delvar(VAR_FILEFILT) ;
- }
- /* build a list of files to restore using the excludlist*/
- restorelist(backhead,TRUE, psionpath, restoredir) ;
- /* do the restore */
- if (findvar(VAR_VERBOSE) != NULL)
- printf("RESTORE: Stage 2, Putting files\n");
- dorestore(psionpath,backhead, restoredir) ;
- /* free the accumulated data structures */
- closebackuplist(backhead) ;
- /* reset the VAR_FILEFILT if it was set */
- if (filefilterwasset)
- addvar(VAR_FILEFILT,"") ;
- timeend = time(NULL) ;
- if (findvar(VAR_VERBOSE) != NULL)
- {
- printf("RESTORE: %s of %s to %s complete\n", incremental ? "Incremental restore" : "Restore", restoredir, psionpath) ;
- printf("RESTORE: %s\n", ctime(&timeend)) ;
- printf("RESTORE: %d directories, %d files\n", dircount, filecount) ;
- printf("RESTORE: Time taken %d seconds\n", (int) timeend - timestart) ;
- }
-
- }
- restorelist(currnode,exclude, psionpath, restoredir)
- struct backupentry *currnode ;
- int exclude ;
- char * psionpath, *restoredir ;
- {
- int i ;
- char tmp[100], nodepath[1024], tmp1[1024];
- FILE * fd ;
- struct backupentry *child ;
- int nodepathlen ;
- if (debugcall >= BACKUPCALLDEBUG)
- fprintf(stderr, "CALL: restorelist (currnode->pname = %s, exclude = %d, psionpath = %s, restoredir = %s)\n", currnode->pname, exclude, psionpath, restoredir) ;
- /* are we using the excludelist ? if so is thie item on it ? */
- if (exclude)
- {
- if (currnode->exclude = findexclude(currnode->pname))
- return ;
- }
- /* if the current node is a file set the flg and and check
- that the file mod has not changed, if so exclude it */
- if ((currnode->nodetype=restorepathtype(currnode->pname)) == BACKUPNODEFILE)
- {
- if (incremental)
- currnode->exclude = restoremodified(currnode->pname,psionpath, restoredir) ;
- return ;
- }
- /* check that it realy is a directory */
- if (currnode->nodetype == BACKUPNODEUNKNOWN)
- return ;
- /* the current node is a directory, Lets work on it */
- /* build up the list command */
- sprintf(tmp, "ls %s > %s", currnode->pname, BACKUPLISTNAME) ;
- /* list the current node use unix to do the work ! */
- system(tmp) ;
- /* we now have a list in BACKUPLISTNAME of all the items in this node lets get them !*/
- if ((fd = fopen(BACKUPLISTNAME,"r")) == NULL)
- {
- printf("ERROR: Error in opening restore temporary file quiting\n") ;
- psdc() ;
- }
- while (fgets(tmp1,120,fd) != NULL)
- /* for each item in the current node */
- {
- /* as we use ls which does not give the entire pathname add
- currnode->pname to the string */
- sprintf(nodepath, "%s/%s", currnode->pname, tmp1) ;
- /* if the last char is newline, removeit, cmdintr
- doesnot like it */
- nodepathlen = strlen(nodepath) ;
- if (nodepath[nodepathlen -1] == '\n')
- nodepath[nodepathlen -1] = 0 ;
- if (debugbackup)
- printf("Now working on %s\n", nodepath) ;
- /* create a new node and install its name */
- backupaddchild(currnode,nodepath) ;
- }
- fclose(fd) ;
- /* remove the tmp file so others running the program won't
- have a problem */
- if (unlink (BACKUPLISTNAME))
- printf("ERROR: Error in removing restore temporary file\n") ;
- /* get ready to scan the children in the current node */
- child = currnode->children ;
- /* for each item in the current node */
- while(child != NULL)
- {
- /* recursively call restorelist to work on the new item */
- restorelist(child,exclude, psionpath, restoredir) ;
- child = child->next ;
- }
- }
- restorepathtype(path)
- char * path ;
- {
- struct stat sunstat ;
- int ret ;
- if (debugcall >= BACKUPCALLDEBUG)
- fprintf(stderr, "CALL: restorepathtype(path = %s)\n", path) ;
- ret = stat(path, &sunstat) ;
- if (S_ISDIR(sunstat.st_mode))
- {
- return(BACKUPNODEDIR) ;
- }
- else if (S_ISREG(sunstat.st_mode))
- {
- return(BACKUPNODEFILE);
- }
- else
- {
- return(BACKUPNODEUNKNOWN) ;
- }
- }
-
- dorestore(path,currnode, restoredir)
- char * path , *restoredir;
- struct backupentry * currnode ;
- {
- int i ;
- char * tmp ;
- char targetpath [1024] ;
- char cmd[2048] ;
- char resp[10] ;
- struct backupentry * child ;
- if (debugcall >= BACKUPCALLDEBUG)
- fprintf(stderr, "CALL: dorestore (path = %s, currnode->pname = %s, restoredir = %s)\n",path, currnode->pname, restoredir) ;
- /* check that the current node is not excluded */
- if (currnode->exclude)
- return ;
- /* if the type of the current node is unknown return */
- if (currnode->nodetype == BACKUPNODEUNKNOWN)
- return ;
- /* if the current entry is a file get it and return */
- if (currnode->nodetype == BACKUPNODEFILE)
- {
- /* get it */
- if (debugbackup)
- printf("RESTORE: Putting %s\n", currnode->pname) ;
- /* build up the command to do the put */
- restorebuildpath(currnode->pname, path, targetpath, restoredir) ;
- sprintf(cmd, "put %s %s", targetpath, currnode->pname) ;
- if (debugbackup)
- printf("RESTORE: doing %s\n",cmd) ;
- /* if VAR_BACKUPNODO just print the command */
- if (findvar(VAR_BACKUPNODO) != NULL)
- {
- printf("RESTORE: Would have done \"%s\"\n", cmd);
- }
- else
- {
- /* if VAR_RESTOREASK check to see if we went to do this one */
- if (findvar(VAR_RESTOREASK) != NULL)
- {
- printf("RESTORE: Do you want to restore file %s ? (y/n) ", currnode->pname) ;
- fgets(resp, sizeof(resp), stdin) ;
- if ((resp[0] == 'y') || (resp[0] == 'Y'))
- {
- cmdintr(cmd) ;
- }
- }
- else
- {
- cmdintr(cmd) ;
- }
- }
- /* increment the filecount */
- filecount ++ ;
- return ;
- }
- else
- {
- /* the current entry is a directory, make it in the filesystem and then look at all its children */
- /* make the directory */
- if (debugbackup)
- printf("RESTORE: Making dir %s\n",currnode->pname) ;
- /* build up the command to do the mkdir */
- strcpy (cmd, "mkdir ") ;
- restorebuildpath(currnode->pname, path, targetpath, restoredir) ;
- strcat(cmd,targetpath) ;
- if (debugbackup)
- printf("RESTORE: doing cmdintr(%s)\n", cmd) ;
- /* if VAR_BACKUPNODO just print the command */
- if (findvar(VAR_BACKUPNODO) != NULL)
- {
- printf("RESTORE: Would have done \"%s\"\n", cmd) ;
- }
- else
- {
- /* if VAR_RESTOREASK check to see if we went to do this one */
- if (findvar(VAR_RESTOREASK) != NULL)
- {
- printf("RESTORE: Do you want to restore directory %s ? (y/n) ", currnode->pname) ;
- fgets(resp, sizeof(resp), stdin) ;
- if ((resp[0] == 'y') || (resp[0] == 'Y'))
- {
- cmdintr(cmd) ;
- }
- else
- {
- printf("RESTORE: Warning, as you are not restoring up directory %s none of its children will be backed up\n", currnode->pname) ;
- return ;
- }
- }
- else
- {
- cmdintr(cmd) ;
- }
- }
- /* for each entry in the current get the children */
- child = currnode->children ;
- while(child != NULL)
- {
- dorestore(path,child, restoredir) ;
- child = child -> next ;
- }
- /* no children left increment the dircount and return */
- dircount ++ ;
- return ;
- }
- }
-
- restorebuildpath(path, root, target,purge)
- char * path, *root, *target, *purge ;
- {
- int i ;
- char tmp[1024], *tmpptr;
- /* path is the path to munge (add root drive:, change all / to \) */
- /* also change all S to $, if purge exists at the front of the path*/
- /* remove those characters if they match*/
- /* root is the psion directory at the top of this tree (e.g. m:) */
- /* target is the place to put the resultant string */
- if (debugcall >= BACKUPCALLDEBUG)
- fprintf(stderr, "CALL: restorebuildpath (path = %s, root = %s target = OMITTED, purge = %s )\n",path, root, purge) ;
-
- strcpy(tmp, path) ;
- tmpptr = tmp ;
- /* whilst the two are the same and neither are the end of string move
- allong the two removing characters from the front of the array */
- while ((purge[0] == tmpptr[0]) && (purge[0] != '\0') && (tmpptr[0] != '\0'))
- {
- purge ++ ;
- tmpptr ++ ;
- }
- /* change the / to \ and S to $ */
- for (i = 0 ; i < (int) strlen(tmpptr) ; i ++ )
- {
- if (tmpptr[i] == 'S')
- {
- tmpptr[i] = '$' ;
- }
- else if (tmpptr[i] == '/')
- {
- tmpptr[i] = '\\' ;
- }
- }
- /* build the output name */
- strcpy(target, root) ;
- strcat(target,tmpptr) ;
- if (debugcall >= BACKUPCALLDEBUG)
- fprintf(stderr, "EXIT: restorebuildpath (target = %s)\n", target) ;
- }
- restoremodified(sunname, psiondir, restdir)
- char * sunname, *psiondir , *restdir;
- {
- char psionpath [1024] ;
- char tmp [1000] ;
- long pstime , suntime ;
- struct stat sunstat ;
- int ret ;
- if (debugcall >= BACKUPCALLDEBUG)
- fprintf(stderr, "CALL: restoremodified (sunname = %s, psiondir = %s, restdir = %s )\n",sunname, psiondir, restdir) ;
-
- /* has the file on the psion been changes more recently
- than the one on the sun ? if so return FALSE else TRUE*/
-
-
- /* create a temporary copy of the sunname so we can work on it */
- strcpy(tmp, sunname) ;
- /* get the psionname for this */
- restorebuildpath(tmp, psiondir, psionpath, restdir) ;
- pssetpath(psionpath) ;
- /* does the psion file exist ? if so get the time else FALSE */
- if (psep())
- pstime = psgetmodtime() ;
- else
- return(FALSE) ;
- ret = stat(sunname, &sunstat) ;
-
-
- #ifndef SVR4
- if (debugbackup)
- printf("ret = %d suntime = %ld pstime = %ld\n", ret, sunstat.st_mtime, pstime) ;
- if (pstime > (sunstat.st_mtime + CLOCKDIFF))
- return(TRUE) ;
- else
- return(FALSE) ;
- #else
- if (debugbackup)
- printf("ret = %d suntime = %ld pstime = %ld\n", ret, sunstat.st_mtim.tv_sec, pstime) ;
-
- if (pstime > (sunstat.st_mtim.tv_sec + CLOCKDIFF))
- return(TRUE) ;
- else
- return(FALSE) ;
- #endif
- }
-