void ScanFileOrFolder::run() { stopped=false; ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"start the listing with destination: "+destination+", mode: "+QString::number(mode)); destination=resolvDestination(destination).absoluteFilePath(); if(stopIt) { stopped=true; return; } if(fileErrorAction==FileError_Skip) { stopped=true; return; } int sourceIndex=0; while(sourceIndex<sources.size()) { ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"size source to list: "+QString::number(sourceIndex)+text_slash+QString::number(sources.size())); if(stopIt) { stopped=true; return; } QFileInfo source=sources.at(sourceIndex); if(source.isDir() && !source.isSymLink()) { /* Bad way; when you copy c:\source\folder into d:\destination, you wait it create the folder d:\destination\folder //listFolder(source.absoluteFilePath()+QDir::separator(),destination); listFolder(source.absoluteFilePath()+text_slash,destination);//put unix separator because it's transformed into that's under windows too */ //put unix separator because it's transformed into that's under windows too QString tempString=QFileInfo(destination).absoluteFilePath(); if(!tempString.endsWith(text_slash) && !tempString.endsWith(text_antislash)) tempString+=text_slash; tempString+=TransferThread::resolvedName(source); if(moveTheWholeFolder && mode==Ultracopier::Move && !QFileInfo(tempString).exists() && driveManagement.isSameDrive(source.absoluteFilePath(),tempString)) { ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,QStringLiteral("tempString: %1 move and not exists").arg(tempString)); ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,QStringLiteral("do real move: %1 to %2").arg(source.absoluteFilePath()).arg(tempString)); emit addToRealMove(source.absoluteFilePath(),tempString); } else { ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,QStringLiteral("tempString: %1 normal listing, blacklist size: %2").arg(tempString).arg(blackList.size())); listFolder(source.absoluteFilePath(),tempString); } } else { ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,QStringLiteral("source: %1 is file or symblink").arg(source.absoluteFilePath())); emit fileTransfer(source,destination+text_slash+source.fileName(),mode); } sourceIndex++; } stopped=true; if(stopIt) return; emit finishedTheListing(); }
static int ev_handler(struct mg_connection *conn, enum mg_event ev) { switch (ev) { case MG_AUTH: return MG_TRUE; case MG_REQUEST: if (!strcmp(conn->uri, "/ind")) { // handle_restful_call(conn); show_index(conn); return MG_TRUE; } else if (!strcmp(conn->uri, "/transfer")) { fileTransfer(conn); return MG_TRUE; } mg_send_file(conn, "index.html", s_no_cache_header); return MG_MORE; default: return MG_FALSE; } }
/* * handleUpload(): This function delivers the upload functionality for the server. * This function co-ordinates the main functions of the server such as checking user validity, and file transfer */ int handleUpload(int connID) { int i, check = TRUE; time_t start, end; //Show the start time of upload start = time(0); (void) printf("Start Time %s\n", ctime(&start)); //function that checks if its new user or existing user and creates directory checkUserDir(connID); //function that accepts file from client and saves to local storage fileTransfer(connID); //Display the end time and calculate the total time taken for upload end = time(0); (void) printf("End Time %s\n", ctime(&end)); (void) printf("Total Time %lu\n", (end - start)); //Loop through to check if connection was from client or server for (i = 0; i < 2; i++) { if (strcmp(clientConn, server_addr_list[i]) == 0) { check = FALSE; break; } } //if connection was from client, initiate data redundancy to send data to other servers if (check) { //start a new thread to perform data redundancy among servers. //Including this we have included all concurrency approaches in our server pthread_t thread1; pthread_create(&thread1, NULL,(void * (*)(void *))dataRedundancyClient, username); pthread_join(thread1, NULL); } return 0; }
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); } }
int solveTransferRemoteFile(diet_profile_t* profile){ std::string srcPath = ""; std::string destUser = ""; std::string srcHost = ""; std::string sessionKey = ""; std::string destHost = ""; std::string destPath = ""; std::string optionsSerialized = ""; std::string srcUserKey = ""; std::string srcUserLogin = ""; std::string srcMachineName = ""; std::string errMsg = ""; std::string finishError = ""; std::string fileTransferSerialized = ""; std::string cmd = ""; diet_string_get(profile, 0, sessionKey); diet_string_get(profile, 1, srcHost); diet_string_get(profile, 2, srcPath); diet_string_get(profile, 3, destHost); diet_string_get(profile, 4, destPath); diet_string_get(profile, 5, optionsSerialized); // reset profile to handle result diet_profile_reset(profile, 2); SessionServer sessionServer (sessionKey); try { int mapperkey; std::string destUserLogin(destUser); std::string destMachineName(destHost); SessionServer sessionServer (sessionKey); // check the source machine // and get the source machine if applied if (destHost != "localhost"){ UMS_Data::Machine_ptr machine = new UMS_Data::Machine(); machine->setMachineId(destHost); MachineServer destMachineServer(machine); destMachineServer.checkMachine(); destMachineName = destMachineServer.getMachineName(); delete machine; } else { destMachineName = destHost; } // get the source machine user login if (destHost != "localhost"){ destUserLogin = UserServer(sessionServer).getUserAccountLogin(destHost); } else { destUserLogin = destUser; } //MAPPER CREATION std::string destCpltPath = destPath; if (destUser.empty()) { destCpltPath = destHost + ":" + destPath; } Mapper *mapper = MapperRegistry::getInstance()->getMapper(vishnu::FMSMAPPERNAME); if (transferMode == File::sync) { if(transferType == File::copy) { mapperkey = mapper->code("vishnu_cp"); } if(transferType == File::move) { mapperkey = mapper->code("vishnu_mv"); } } else{ if (transferType == File::copy) { mapperkey = mapper->code("vishnu_acp"); } if (transferType == File::move) { mapperkey = mapper->code("vishnu_amv"); } } mapper->code(srcHost + ":" + srcPath, mapperkey); mapper->code(destCpltPath, mapperkey); mapper->code(optionsSerialized, mapperkey); cmd = mapper->finalize(mapperkey); // check the sessionKey sessionServer.check(); // get the source Vishnu machine UMS_Data::Machine_ptr machine = new UMS_Data::Machine(); machine->setMachineId(srcHost); MachineServer srcMachineServer(machine); // check the source machine if (srcHost != "localhost"){ srcMachineServer.checkMachine(); srcMachineName = srcMachineServer.getMachineName(); } else { srcMachineName = srcHost; } delete machine; // get the source machine user login if (srcHost != "localhost"){ srcUserLogin = UserServer(sessionServer).getUserAccountLogin(srcHost); } else { srcUserLogin = destUser; } if (destUser.empty()) { // get the destination Vishnu machine machine = new UMS_Data::Machine(); machine->setMachineId(destHost); // check the destination machine if (destHost != "localhost"){ MachineServer destMachineServer(machine); destMachineServer.checkMachine(); // get the destination machineName destMachineName = destMachineServer.getMachineName(); delete machine; } // get the destination machine user login if (destHost != "localhost"){ destUserLogin = UserServer(sessionServer).getUserAccountLogin(destHost); } else { destUserLogin = destUser; } } FMS_Data::CpFileOptions_ptr options_ptr= NULL; if (! vishnu::parseEmfObject(optionsSerialized, options_ptr) ) { throw SystemException(ERRCODE_INVDATA, "solve_Copy: CpFileOptions object is not well built"); } boost::shared_ptr<FileTransferServer> fileTransferServer = \ boost::make_shared<FileTransferServer>(sessionServer, srcHost, destHost, srcPath, destPath); // Perfor the transfer now if (transferMode==File::sync) { if (transferType == File::copy) { fileTransferServer->addCpThread(srcUserLogin, srcMachineName, srcUserKey, destUserLogin, destMachineName, *options_ptr); } if (transferType == File::move) { fileTransferServer->addMvThread(srcUserLogin, srcMachineName, srcUserKey, destUserLogin, destMachineName, *options_ptr); } } else { if (transferType == File::copy) { fileTransferServer->addCpAsyncThread(srcUserLogin, srcMachineName, srcUserKey, destUserLogin, destMachineName, *options_ptr); } if (transferType == File::move) { fileTransferServer->addMvAsyncThread(srcUserLogin, srcMachineName, srcUserKey, destUserLogin, destMachineName, *options_ptr); } } FMS_Data::FMS_DataFactory_ptr ecoreFactory = FMS_Data::FMS_DataFactory::_instance(); boost::scoped_ptr<FMS_Data::FileTransfer> fileTransfer(ecoreFactory->createFileTransfer()); *(fileTransfer.get()) = fileTransferServer->getFileTransfer(); ::ecorecpp::serializer::serializer _ser; fileTransferSerialized = _ser.serialize_str(const_cast<FMS_Data::FileTransfer_ptr>(fileTransfer.get())); //To register the command sessionServer.finish(cmd, vishnu::FMS, vishnu::CMDSUCCESS); } catch (VishnuException& err) { try { sessionServer.finish(cmd, vishnu::FMS, vishnu::CMDFAILED); } catch (VishnuException& fe) { finishError = fe.what(); finishError +="\n"; } err.appendMsgComp(finishError); errMsg = err.buildExceptionString().c_str(); } if (errMsg.empty()){ diet_string_set(profile, 0, "success"); diet_string_set(profile, 1, fileTransferSerialized.c_str()); } else { diet_string_set(profile, 0, "error"); diet_string_set(profile, 1, errMsg); } return 0; }