/* * Copyright (c) 2003,2004 Daniel Bryan * All rights reserved. * * For more information see COPYRIGHT. */ #include #include #include #include #include #if defined(__linux__) #include #endif #include "common.h" #include "misc.h" #include "screen.h" #include "path.h" #include "color.h" #include "screen.h" int statit(char *path,struct stat *st,int cmdline) { if(Rflag) { if(pflag || ((Hflag) && !cmdline)) return (lstat(path,st)); /* do not follow symbolic links */ } return (stat(path,st)); /* follow symbolic links */ } int setperm(char *src,struct stat *st) { struct stat tmp; #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) static struct timeval timea[2]; #endif #if defined(__linux__) struct utimbuf timea; #endif if(!pflag) return 1; #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) TIMESPEC_TO_TIMEVAL(&timea[0],&st->st_atimespec); TIMESPEC_TO_TIMEVAL(&timea[1],&st->st_mtimespec); if(utimes(src,timea) == -1) { logadds(LOG_ERR,"utimes: %s: %s",src,strerror(errno)); } #endif #if defined(__linux__) timea.actime = st->st_atime; timea.modtime = st->st_mtime; if(utime(src,&timea) == -1) { logadds(LOG_ERR,"utime: %s: %s",src,strerror(errno)); } #endif tmp.st_mode &= (S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO); if(st->st_uid != tmp.st_uid || st->st_gid != tmp.st_gid) { if(chown(src,st->st_uid,st->st_gid) == -1 && errno != EPERM) { logadds(LOG_ERR,"chown: %s: %s",src,strerror(errno)); } } if(chmod(src,st->st_mode) == -1) { logadds(LOG_ERR,"chmod: %s: %s",src,strerror(errno)); } #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) if(chflags(src,st->st_flags) == -1) { logadds(LOG_ERR,"chflags: %s: %s",src,strerror(errno)); } #endif return 0; } void done(int i) { logadds(LOG_MSG,"",NULL,NULL); if(use_curses && scrn_state == SCRN_SUMMARY) { endwin(); use_curses = 0; } if(mflag) { if(totalfiles / i == 1 && i == 1) { logaddi(LOG_MSG,"%d file copied %d time",totalfiles / i,i); logaddi(LOG_MSG,"%d failed",totalfiles-goodcp,0); } else if(totalfiles / i == 1) { logaddi(LOG_MSG,"%d file copied %d times",totalfiles / i,i); logaddi(LOG_MSG,"%d failed",totalfiles-goodcp,0); } else if(i == 1) { logaddi(LOG_MSG,"%d files copied %d time",totalfiles / i,i); logaddi(LOG_MSG,"%d failed",totalfiles-goodcp,0); } else { logaddi(LOG_MSG,"%d files copied %d times",totalfiles / i,i); logaddi(LOG_MSG,"%d failed",totalfiles-goodcp,0); } } else { if(goodcp == 1) { logaddi(LOG_MSG,"%d file copied, %d failed",goodcp,totalfiles-goodcp); } else { logaddi(LOG_MSG,"%d files copied, %d failed",goodcp,totalfiles-goodcp); } } if(use_curses && scrn_state == SCRN_KEYWAIT) wgetch(logw); exit_pre(); exit(ret); } void exit_pre() { if(databuf != NULL) free(databuf); if(use_curses) endwin(); return; } void usage() { logadds(LOG_MSG,"",NULL,NULL); logadds(LOG_MSG,"usage:",NULL,NULL); logadds(LOG_MSG,"options %s %s", \ "[-vdpVmhtu] [-I | -i | -f | -n] ", \ "[-R [-P | -H | -L]] [-b bytes]"); logadds(LOG_MSG,"vcp [options] src dest",NULL,NULL); logadds(LOG_MSG,"vcp [options] src1 src2 .. destdir",NULL,NULL); logadds(LOG_MSG,"vcp [options -m] src dest1 dest2 ..",NULL,NULL); logadds(LOG_MSG,"'vcp -h' for option help",NULL,NULL); exit_pre(); exit(1); } void check_iloop(char *args[], char *test) { int i = 0; while(args[i] != NULL) { if((strcmp(args[i],test) == 0) || (strcmp(args[i],".") == 0)) { logadds(LOG_ERR,"Warning: possible infinite loop (%s)",args[i],NULL); } i++; } return; } void print_error(char *src, int errno_) { if(errno_ == ENAMETOOLONG) pathlong(src,src); else logadds(LOG_ERR,"%s: %s",src,strerror(errno_)); return; } void flags_print() { char buf[15]; buf[0] = '\0'; if(vflag) strcat(buf,"v"); if(tflag) strcat(buf,"t"); if(dflag) strcat(buf,"d"); if(Iflag) strcat(buf,"I"); if(iflag) strcat(buf,"i"); if(fflag) strcat(buf,"f"); if(nflag) strcat(buf,"n"); if(Rflag) strcat(buf,"R"); if(Hflag) strcat(buf,"H"); if(Pflag) strcat(buf,"P"); if(Lflag) strcat(buf,"L"); if(mflag) strcat(buf,"m"); if(uflag) strcat(buf,"u"); logadds(LOG_MSG,"Flags -%s",buf,NULL); return; } int cntfiles(char *args[],int fts_opt) { int total = 0; FTS *ftsd; FTSENT *ftsf; if((ftsd = fts_open(args,fts_opt,0)) == NULL) return 0; while((ftsf = fts_read(ftsd)) != NULL) { switch(ftsf->fts_info) { /* count the file even if invalid */ case FTS_F: case FTS_NS: case FTS_NSOK: case FTS_SL: case FTS_SLNONE: case FTS_DEFAULT: if(!ftsf->fts_number) { ftsf->fts_number = 1; total++; } } } return total; } #define CONF_SIZE 64 int conf_readval(int file, char *buf) { int i; for(i=0;i