//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 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); } }