// Recursively copy files or directories from srcfile to dstfile, overwriting dstfile if allowed bool FXFile::copyFiles(const FXString& srcfile,const FXString& dstfile,bool overwrite){ if(srcfile!=dstfile){ FXString name,linkname; FXStat srcstat; FXStat dststat; FXTRACE((100,"FXFile::copyFiles(%s,%s)\n",srcfile.text(),dstfile.text())); if(FXStat::statLink(srcfile,srcstat)){ // Destination is a directory? if(FXStat::statLink(dstfile,dststat)){ if(!dststat.isDirectory()){ if(!overwrite) return false; //FXTRACE((100,"FXFile::remove(%s)\n",dstfile.text())); if(!FXFile::remove(dstfile)) return false; } } // Source is a directory if(srcstat.isDirectory()){ // Make destination directory if needed if(!dststat.isDirectory()){ //FXTRACE((100,"FXDir::create(%s)\n",dstfile.text())); // Make directory if(!FXDir::create(dstfile,srcstat.mode()|FXIO::OwnerWrite)) return false; } // Open source directory FXDir dir(srcfile); // Copy source directory while(dir.next()){ // Next name name=dir.name(); // Skip '.' and '..' if(name[0]=='.' && (name[1]=='\0' || (name[1]=='.' && name[2]=='\0'))) continue; // Recurse if(!FXFile::copyFiles(srcfile+PATHSEP+name,dstfile+PATHSEP+name,overwrite)) return false; } // OK return true; } // Source is a file if(srcstat.isFile()){ //FXTRACE((100,"FXFile::copyFile(%s,%s)\n",srcfile.text(),dstfile.text())); // Simply copy if(!FXFile::copy(srcfile,dstfile,overwrite)) return false; // OK return true; } // Source is symbolic link: make a new one if(srcstat.isLink()){ linkname=FXFile::symlink(srcfile); FXTRACE((100,"symlink(%s,%s)\n",srcfile.text(),dstfile.text())); // New symlink to whatever old one referred to if(!FXFile::symlink(srcfile,dstfile)) return false; // OK return true; } // Source is fifo: make a new one if(srcstat.isFifo()){ //FXTRACE((100,"FXPipe::create(%s)\n",dstfile.text())); #if defined(FX_FOXCOMPAT) && !defined(FX_DISABLEGUI) // Make named pipe if(!FXPipe::create(dstfile,srcstat.mode())) return false; #endif // OK return true; } /* // Source is device: make a new one if(S_ISBLK(status1.st_mode) || S_ISCHR(status1.st_mode) || S_ISSOCK(status1.st_mode)){ FXTRACE((100,"mknod(%s)\n",newfile.text())); return ::mknod(newfile.text(),status1.st_mode,status1.st_rdev)==0; } */ } } return false; }
static void copyConfigFiles(const FXString& srcfile,const FXString& dstfile, FXString &errors,FXint level) { if (srcfile!=dstfile) { FXString name,linkname; FXStat srcstat; FXStat dststat; if (DoStat(srcfile,srcstat)) { if (DoStat(dstfile,dststat)) { errno=0; Error(_("File exists"), dstfile); return; } if (srcstat.isDirectory()) { # ifdef WIN32 if ((level==2) && (FXPath::name(srcfile)=="servers")) { FXDir::remove(srcfile); return; } # endif if (!dststat.isDirectory()) { if (!FXDir::create(dstfile,srcstat.mode()|FXIO::OwnerWrite)) { Error(_("Create failed"), dstfile); return; } } FXDir dir(srcfile); if (dir.isOpen()) { while(dir.next(name)) { if (name[0]=='.' && (name[1]=='\0' || (name[1]=='.' && name[2]=='\0'))) continue; copyConfigFiles(srcfile+PATHSEP+name,dstfile+PATHSEP+name,errors,level+1); } } else { Error(_("Access failed"), srcfile); } return; } FXString newname=dstfile.text(); # ifndef WIN32 if ((level==2) && ((FXPath::name(srcfile)=="settings")||(FXPath::name(srcfile)=="styles"))) { newname+=".rc"; } # endif if (srcstat.isFile()) { if (!FXFile::copy(srcfile,newname,false)) { Error(_("Copy failed"), srcfile); } return; } if (srcstat.isLink()) { linkname=FXFile::symlink(srcfile); if (!FXFile::symlink(linkname,newname)) { Error(_("Link failed"), newname); } return; } if (srcstat.isFifo()) { if (!FXPipe::create(dstfile,srcstat.mode())) { Error(_("Create fifo failed"), dstfile); } return; } if (srcstat.isSocket()) { errno=0; Error(_("Ignored socket"), srcfile); return; } if (srcstat.isCharacter()||srcstat.isBlock()) { errno=0; Error(_("Ignored device node"), srcfile); return; } } } }