//show one new dialog if needed void copyEngine::showOneNewDialog() { if(stopIt) return; ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"alreadyExistsQueue.size(): "+QString::number(alreadyExistsQueue.size())); ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"errorQueue.size(): "+QString::number(errorQueue.size())); loop_size=alreadyExistsQueue.size(); while(loop_size>0) { if(alreadyExistsQueue.first().transfer!=NULL) { fileAlreadyExists(alreadyExistsQueue.first().source, alreadyExistsQueue.first().destination, alreadyExistsQueue.first().isSame, alreadyExistsQueue.first().transfer, true); } else if(alreadyExistsQueue.first().scan!=NULL) folderAlreadyExists(alreadyExistsQueue.first().source, alreadyExistsQueue.first().destination, alreadyExistsQueue.first().isSame, alreadyExistsQueue.first().scan, true); else ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Critical,"bug, no thread actived"); alreadyExistsQueue.removeFirst(); loop_size--; } loop_size=errorQueue.size(); while(errorQueue.size()>0) { if(errorQueue.first().transfer!=NULL) errorOnFile(errorQueue.first().inode,errorQueue.first().errorString,errorQueue.first().transfer,true); else if(errorQueue.first().scan!=NULL) errorOnFolder(errorQueue.first().inode,errorQueue.first().errorString,errorQueue.first().scan,true); else if(errorQueue.first().mkPath) mkPathErrorOnFolder(errorQueue.first().inode,errorQueue.first().errorString,true); else if(errorQueue.first().rmPath) rmPathErrorOnFolder(errorQueue.first().inode,errorQueue.first().errorString,true); else ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Critical,"bug, no thread actived"); errorQueue.removeFirst(); loop_size--; } }
void MkPath::internalDoThisPath() { if(waitAction || pathList.isEmpty()) return; ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"start: "+pathList.first()); if(!dir.exists(pathList.first())) if(!dir.mkpath(pathList.first())) { if(!dir.exists(pathList.first())) { if(stopIt) return; waitAction=true; ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Warning,"Unable to remove the folder: "+pathList.first()); emit errorOnFolder(pathList.first(),tr("Unable to create the folder")); return; } } pathList.removeFirst(); emit firstFolderFinish(); checkIfCanDoTheNext(); }
QFileInfo ScanFileOrFolder::resolvDestination(const QFileInfo &destination) { QFileInfo newDestination=destination; while(newDestination.isSymLink()) { ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,QStringLiteral("resolv destination to: %1").arg(newDestination.symLinkTarget())); if(QFileInfo(newDestination.symLinkTarget()).isAbsolute()) newDestination.setFile(newDestination.symLinkTarget()); else newDestination.setFile(newDestination.absolutePath()+text_slash+newDestination.symLinkTarget()); } do { fileErrorAction=FileError_NotSet; if(isBlackListed(destination)) { ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Warning,QStringLiteral("isBlackListed: %1").arg(destination.absoluteFilePath())); emit errorOnFolder(destination,tr("Blacklisted folder"),ErrorType_Folder); waitOneAction.acquire(); ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"actionNum: "+QString::number(fileErrorAction)); } } while(fileErrorAction==FileError_Retry || fileErrorAction==FileError_PutToEndOfTheList); return newDestination; }
void MkPath::internalDoThisPath() { if(waitAction || pathList.isEmpty()) return; ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,QStringLiteral("source: %1, destination: %2, move: %3").arg(pathList.first().source.absoluteFilePath()).arg(pathList.first().destination.absoluteFilePath()).arg(pathList.first().actionType)); #ifdef ULTRACOPIER_PLUGIN_RSYNC if(pathList.first().actionType==ActionType_RmSync) { if(pathList.first().destination.isFile()) { QFile removedFile(pathList.first().destination.absoluteFilePath()); if(!removedFile.remove()) { if(stopIt) return; waitAction=true; ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Warning,"Unable to remove the inode: "+pathList.first().destination.absoluteFilePath()+", error: "+removedFile.errorString()); emit errorOnFolder(pathList.first().destination,removedFile.errorString()); return; } } else if(!rmpath(pathList.first().destination.absoluteFilePath())) { if(stopIt) return; waitAction=true; ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Warning,"Unable to remove the inode: "+pathList.first().destination.absoluteFilePath()); emit errorOnFolder(pathList.first().destination,tr("Unable to remove")); return; } pathList.removeFirst(); emit firstFolderFinish(); checkIfCanDoTheNext(); return; } #endif doTheDateTransfer=false; if(keepDate) { if(!pathList.first().source.exists()) { ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Warning,"the sources not exists: "+pathList.first().source.absoluteFilePath()); doTheDateTransfer=false; } else if(maxTime>=pathList.first().source.lastModified()) { ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Warning,"the sources is older to copy the time: "+pathList.first().source.absoluteFilePath()+": "+maxTime.toString("dd.MM.yyyy hh:mm:ss.zzz")+">="+pathList.first().source.lastModified().toString("dd.MM.yyyy hh:mm:ss.zzz")); doTheDateTransfer=false; } else { doTheDateTransfer=readFileDateTime(pathList.first().source); /*if(!doTheDateTransfer) { if(stopIt) return; waitAction=true; ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Warning,"Unable to get source folder time: "+pathList.first().source.absoluteFilePath()); emit errorOnFolder(pathList.first().source,tr("Unable to get time")); return; }*/ } } if(dir.exists(pathList.first().destination.absoluteFilePath()) && pathList.first().actionType==ActionType_RealMove) pathList.first().actionType=ActionType_MovePath; if(pathList.first().actionType!=ActionType_RealMove) { if(!dir.exists(pathList.first().destination.absoluteFilePath())) if(!dir.mkpath(pathList.first().destination.absoluteFilePath())) { if(!dir.exists(pathList.first().destination.absoluteFilePath())) { if(stopIt) return; waitAction=true; ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Warning,"Unable to make the folder: "+pathList.first().destination.absoluteFilePath()); emit errorOnFolder(pathList.first().destination,tr("Unable to create the folder")); return; } } } else { if(!pathList.first().source.exists()) { if(stopIt) return; waitAction=true; ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Warning,"The source folder don't exists: "+pathList.first().source.absoluteFilePath()); emit errorOnFolder(pathList.first().destination,tr("The source folder don't exists")); return; } if(!pathList.first().source.isDir())//it's really an error? { ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Warning,"The source is not a folder: "+pathList.first().source.absoluteFilePath()); /*if(stopIt) return; waitAction=true; emit errorOnFolder(pathList.first().destination,tr("The source is not a folder")); return;*/ } if(pathList.first().destination.absoluteFilePath().startsWith(pathList.first().source.absoluteFilePath()+text_slash)) { ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Warning,"move into it self: "+pathList.first().destination.absoluteFilePath()); int random=rand(); QFileInfo tempFolder=pathList.first().source.absolutePath()+text_slash+QString::number(random); while(tempFolder.exists()) { random=rand(); tempFolder=pathList.first().source.absolutePath()+text_slash+QString::number(random); } if(!dir.rename(pathList.first().source.absoluteFilePath(),tempFolder.absoluteFilePath())) { if(stopIt) return; waitAction=true; ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Warning,"Unable to temporary rename the folder: "+pathList.first().destination.absoluteFilePath()); emit errorOnFolder(pathList.first().destination,tr("Unable to temporary rename the folder")); return; } /* http://doc.qt.io/qt-5/qdir.html#rename * On most file systems, rename() fails only if oldName does not exist, or if a file with the new name already exists. if(!dir.mkpath(pathList.first().destination.absolutePath())) { if(!dir.exists(pathList.first().destination.absolutePath())) { if(stopIt) return; waitAction=true; ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Warning,"Unable to make the folder: "+pathList.first().destination.absoluteFilePath()); emit errorOnFolder(pathList.first().destination,tr("Unable to create the folder")); return; } }*/ if(!dir.rename(tempFolder.absoluteFilePath(),pathList.first().destination.absoluteFilePath())) { if(stopIt) return; waitAction=true; ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Warning,"Unable to do the final real move the folder: "+pathList.first().destination.absoluteFilePath()); emit errorOnFolder(pathList.first().destination,tr("Unable to do the final real move the folder")); return; } } else { /* http://doc.qt.io/qt-5/qdir.html#rename * On most file systems, rename() fails only if oldName does not exist, or if a file with the new name already exists. if(!dir.mkpath(pathList.first().destination.absolutePath())) { if(!dir.exists(pathList.first().destination.absolutePath())) { if(stopIt) return; waitAction=true; ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Warning,"Unable to make the folder: "+pathList.first().destination.absoluteFilePath()); emit errorOnFolder(pathList.first().destination,tr("Unable to create the folder")); return; } }*/ if(!dir.rename(pathList.first().source.absoluteFilePath(),pathList.first().destination.absoluteFilePath())) { if(stopIt) return; waitAction=true; ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Warning,"Unable to make the folder: from: "+pathList.first().source.absoluteFilePath()+", soruce exists: "+QString::number(QDir(pathList.first().source.absoluteFilePath()).exists())+", to: "+pathList.first().destination.absoluteFilePath()+", destination exist: "+QString::number(QDir(pathList.first().destination.absoluteFilePath()).exists())); emit errorOnFolder(pathList.first().destination,tr("Unable to move the folder")); return; } } } if(doTheDateTransfer) if(!writeFileDateTime(pathList.first().destination)) { if(!pathList.first().destination.exists()) ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Warning,"Unable to set destination folder time (not exists): "+pathList.first().destination.absoluteFilePath()); else if(!pathList.first().destination.isDir()) ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Warning,"Unable to set destination folder time (not a dir): "+pathList.first().destination.absoluteFilePath()); else ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Warning,"Unable to set destination folder time: "+pathList.first().destination.absoluteFilePath()); /*if(stopIt) return; waitAction=true; emit errorOnFolder(pathList.first().source,tr("Unable to set time")); return;*/ } if(doRightTransfer && pathList.first().actionType!=ActionType_RealMove) { QFile source(pathList.first().source.absoluteFilePath()); QFile destination(pathList.first().destination.absoluteFilePath()); if(!destination.setPermissions(source.permissions())) { ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Warning,"Unable to set the right: "+pathList.first().destination.absoluteFilePath()); /*if(stopIt) return; waitAction=true; emit errorOnFolder(pathList.first().source,tr("Unable to set the access-right")); return;*/ } } if(pathList.first().actionType==ActionType_MovePath) { if(!rmpath(pathList.first().source.absoluteFilePath())) { if(stopIt) return; waitAction=true; ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Warning,"Unable to remove the source folder: "+pathList.first().destination.absoluteFilePath()); emit errorOnFolder(pathList.first().source,tr("Unable to remove")); return; } } pathList.removeFirst(); emit firstFolderFinish(); checkIfCanDoTheNext(); }
void ScanFileOrFolder::listFolder(QFileInfo source,QFileInfo destination) { ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,QStringLiteral("source: %1 (%2), destination: %3 (%4)").arg(source.absoluteFilePath()).arg(source.isSymLink()).arg(destination.absoluteFilePath()).arg(destination.isSymLink())); if(stopIt) return; destination=resolvDestination(destination); if(stopIt) return; if(fileErrorAction==FileError_Skip) return; //if is same if(source.absoluteFilePath()==destination.absoluteFilePath()) { emit folderAlreadyExists(source,destination,true); waitOneAction.acquire(); QString destinationSuffixPath; switch(folderExistsAction) { case FolderExists_Merge: break; case FolderExists_Skip: return; break; case FolderExists_Rename: ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"destination before rename: "+destination.absoluteFilePath()); if(newName.isEmpty()) { ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"pattern: "+folder_isolation.pattern()); //resolv the new name destinationSuffixPath=destination.baseName(); int num=1; do { if(num==1) { if(firstRenamingRule.isEmpty()) destinationSuffixPath=tr("%1 - copy").arg(destination.baseName()); else { destinationSuffixPath=firstRenamingRule; destinationSuffixPath.replace(QStringLiteral("%name%"),destination.baseName()); } } else { if(otherRenamingRule.isEmpty()) destinationSuffixPath=tr("%1 - copy (%2)").arg(destination.baseName()).arg(num); else { destinationSuffixPath=otherRenamingRule; destinationSuffixPath.replace(QStringLiteral("%name%"),destination.baseName()); destinationSuffixPath.replace(QStringLiteral("%number%"),QString::number(num)); } } num++; if(destination.completeSuffix().isEmpty()) destination.setFile(destination.absolutePath()+text_slash+destinationSuffixPath); else destination.setFile(destination.absolutePath()+text_slash+destinationSuffixPath+text_dot+destination.completeSuffix()); } while(destination.exists()); } else { ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"use new name: "+newName); destinationSuffixPath = newName; } destination.setFile(destination.absolutePath()+text_slash+destinationSuffixPath); ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"destination after rename: "+destination.absoluteFilePath()); break; default: return; break; } } //check if destination exists if(checkDestinationExists) { if(destination.exists()) { emit folderAlreadyExists(source,destination,false); waitOneAction.acquire(); QString destinationSuffixPath; switch(folderExistsAction) { case FolderExists_Merge: break; case FolderExists_Skip: return; break; case FolderExists_Rename: ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"destination before rename: "+destination.absoluteFilePath()); if(newName.isEmpty()) { //resolv the new name QFileInfo destinationInfo; int num=1; do { if(num==1) { if(firstRenamingRule.isEmpty()) destinationSuffixPath=tr("%1 - copy").arg(destination.baseName()); else { destinationSuffixPath=firstRenamingRule; destinationSuffixPath.replace(QStringLiteral("%name%"),destination.baseName()); } } else { if(otherRenamingRule.isEmpty()) destinationSuffixPath=tr("%1 - copy (%2)").arg(destination.baseName()).arg(num); else { destinationSuffixPath=otherRenamingRule; destinationSuffixPath.replace(QStringLiteral("%name%"),destination.baseName()); destinationSuffixPath.replace(QStringLiteral("%number%"),QString::number(num)); } } destinationInfo.setFile(destinationInfo.absolutePath()+text_slash+destinationSuffixPath); num++; } while(destinationInfo.exists()); } else { ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"use new name: "+newName); destinationSuffixPath = newName; } if(destination.completeSuffix().isEmpty()) destination.setFile(destination.absolutePath()+text_slash+destinationSuffixPath); else destination.setFile(destination.absolutePath()+text_slash+destinationSuffixPath+QStringLiteral(".")+destination.completeSuffix()); ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"destination after rename: "+destination.absoluteFilePath()); break; default: return; break; } } } //do source check //check of source is readable do { fileErrorAction=FileError_NotSet; if(!source.isReadable() || !source.isExecutable() || !source.exists() || !source.isDir()) { if(!source.isDir()) emit errorOnFolder(source,tr("This is not a folder")); else if(!source.exists()) emit errorOnFolder(source,tr("The folder does exists")); else emit errorOnFolder(source,tr("The folder is not readable")); waitOneAction.acquire(); ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"actionNum: "+QString::number(fileErrorAction)); } } while(fileErrorAction==FileError_Retry); do { QDir tempDir(source.absoluteFilePath()); fileErrorAction=FileError_NotSet; if(!tempDir.isReadable() || !tempDir.exists()) { emit errorOnFolder(source,tr("Problem with name encoding")); waitOneAction.acquire(); ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"actionNum: "+QString::number(fileErrorAction)); } } while(fileErrorAction==FileError_Retry); if(stopIt) return; /// \todo check here if the folder is not readable or not exists QFileInfoList entryList; if(copyListOrder) entryList=QDir(source.absoluteFilePath()).entryInfoList(QDir::AllEntries|QDir::NoDotAndDotDot|QDir::Hidden|QDir::System,QDir::DirsFirst|QDir::Name|QDir::IgnoreCase);//possible wait time here else entryList=QDir(source.absoluteFilePath()).entryInfoList(QDir::AllEntries|QDir::NoDotAndDotDot|QDir::Hidden|QDir::System);//possible wait time here if(stopIt) return; int sizeEntryList=entryList.size(); emit newFolderListing(source.absoluteFilePath()); if(mode!=Ultracopier::Move) emit addToMkPath(source,destination,sizeEntryList); for (int index=0;index<sizeEntryList;++index) { QFileInfo fileInfo=entryList.at(index); if(stopIt) return; if(haveFilters) { if(reloadTheNewFilters) { QMutexLocker lock(&filtersMutex); QCoreApplication::processEvents(QEventLoop::AllEvents); reloadTheNewFilters=false; this->include=this->include_send; this->exclude=this->exclude_send; } QString fileName=fileInfo.fileName(); if(fileInfo.isDir() && !fileInfo.isSymLink()) { bool excluded=false,included=(include.size()==0); int filters_index=0; while(filters_index<exclude.size()) { if(exclude.at(filters_index).apply_on==ApplyOn_folder || exclude.at(filters_index).apply_on==ApplyOn_fileAndFolder) { if(fileName.contains(exclude.at(filters_index).regex)) { excluded=true; break; } } filters_index++; } if(excluded) {} else { filters_index=0; while(filters_index<include.size()) { if(include.at(filters_index).apply_on==ApplyOn_folder || include.at(filters_index).apply_on==ApplyOn_fileAndFolder) { if(fileName.contains(include.at(filters_index).regex)) { included=true; break; } } filters_index++; } if(!included) {} else listFolder(fileInfo,destination.absoluteFilePath()+text_slash+fileInfo.fileName()); } } else { bool excluded=false,included=(include.size()==0); int filters_index=0; while(filters_index<exclude.size()) { if(exclude.at(filters_index).apply_on==ApplyOn_file || exclude.at(filters_index).apply_on==ApplyOn_fileAndFolder) { if(fileName.contains(exclude.at(filters_index).regex)) { excluded=true; break; } } filters_index++; } if(excluded) {} else { filters_index=0; while(filters_index<include.size()) { if(include.at(filters_index).apply_on==ApplyOn_file || include.at(filters_index).apply_on==ApplyOn_fileAndFolder) { if(fileName.contains(include.at(filters_index).regex)) { included=true; break; } } filters_index++; } if(!included) {} else #ifndef ULTRACOPIER_PLUGIN_RSYNC emit fileTransfer(fileInfo,destination.absoluteFilePath()+text_slash+fileInfo.fileName(),mode); #else { bool sendToTransfer=false; if(!rsync) sendToTransfer=true; else if(!QFile::exists(destination.absoluteFilePath()+"/"+fileInfo.fileName())) sendToTransfer=true; else if(fileInfo.lastModified()!=QFileInfo(destination.absoluteFilePath()+"/"+fileInfo.fileName()).lastModified()) sendToTransfer=true; if(sendToTransfer) emit fileTransfer(fileInfo.absoluteFilePath(),destination.absoluteFilePath()+"/"+fileInfo.fileName(),mode); } #endif } } } else { if(fileInfo.isDir() && !fileInfo.isSymLink())//possible wait time here //listFolder(source,destination,suffixPath+fileInfo.fileName()+QDir::separator()); listFolder(fileInfo,destination.absoluteFilePath()+text_slash+fileInfo.fileName());//put unix separator because it's transformed into that's under windows too else #ifndef ULTRACOPIER_PLUGIN_RSYNC emit fileTransfer(fileInfo,destination.absoluteFilePath()+text_slash+fileInfo.fileName(),mode); #else { bool sendToTransfer=false; if(!rsync) sendToTransfer=true; else if(!QFile::exists(destination.absoluteFilePath()+"/"+fileInfo.fileName())) sendToTransfer=true; else if(fileInfo.lastModified()!=QFileInfo(destination.absoluteFilePath()+"/"+fileInfo.fileName()).lastModified()) sendToTransfer=true; if(sendToTransfer) emit fileTransfer(fileInfo.absoluteFilePath(),destination.absoluteFilePath()+"/"+fileInfo.fileName(),mode); } #endif } } #ifdef ULTRACOPIER_PLUGIN_RSYNC if(rsync) { //check the reverse path here QFileInfoList entryListDestination; if(copyListOrder) entryListDestination=QDir(destination.absoluteFilePath()).entryInfoList(QDir::AllEntries|QDir::NoDotAndDotDot|QDir::Hidden|QDir::System,QDir::DirsFirst|QDir::Name|QDir::IgnoreCase);//possible wait time here else entryListDestination=QDir(destination.absoluteFilePath()).entryInfoList(QDir::AllEntries|QDir::NoDotAndDotDot|QDir::Hidden|QDir::System);//possible wait time here int sizeEntryListDestination=entryListDestination.size(); int index=0; for (int indexDestination=0;indexDestination<sizeEntryListDestination;++indexDestination) { index=0; while(index<sizeEntryList) { if(entryListDestination.at(indexDestination).fileName()==entryList.at(index).fileName()) break; index++; } if(index==sizeEntryList) { //then not found, need be remove emit addToRmForRsync(entryListDestination.at(indexDestination)); } } return; } #endif if(mode==Ultracopier::Move) { ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"source: "+source.absoluteFilePath()+", sizeEntryList: "+QString::number(sizeEntryList)); emit addToMovePath(source,destination,sizeEntryList); } }