📄 staffsservice.cpp
字号:
connection->writeUInt(kSTAFFSContinueCopy); connection->writeUInt(kSTAFFSDirectory); connection->writeString(toDir); //...wait for STAFProc's ack STAFRC_t ack = static_cast<STAFRC_t>(connection->readUInt()); STAFString ackResult = connection->readString(); if (ack != kSTAFOk) updateResultString(outputList, entry, ack, osRC); } // copy current directory if (!onlyDir && fileEnum->isValid()) copyDirectory(fileEnum, fromDir, connection, textExtList, currentEOL, newEOL, doCodepageConvert, level, caseSensitive, outputList, copyDataPtr, toMachine); // Enumerate the directories in the current entry STAFFSEnumPtr directoryEnum = entry->enumerate(kUTF8_STAR, kUTF8_STAR, STAFFSEntryType_t(entryTypesUInt & ~kSTAFFSFile), kSTAFFSNoSort, caseSensitive); // copy sub-directories in current directory for (; directoryEnum->isValid(); directoryEnum->next()) { recurseCopyDir(directoryEnum->entry(), namePattern, extPattern, fromDir, keepEmptyDir, onlyDir, entryTypesUInt, connection, caseSensitive, textExtList, currentEOL, newEOL, level, doCodepageConvert, outputList, copyDataPtr, toMachine); } return kSTAFOk;}STAFRC_t removeChildren(STAFFSEntryPtr entry, const STAFString &namePattern, const STAFString &extPattern, unsigned int entryTypesUInt, STAFFSCaseSensitive_t caseSensitive, STAFObjectPtr &outputList){ STAFFSEnumPtr childEnum = entry->enumerate(namePattern, extPattern, STAFFSEntryType_t(entryTypesUInt), kSTAFFSNoSort, caseSensitive); unsigned int osRC = 0; STAFRC_t rc = kSTAFOk; for (; childEnum->isValid(); childEnum->next()) { STAFFSEntryPtr entry = childEnum->entry(); rc = entry->remove(&osRC); updateResultString(outputList, entry, rc, osRC); } return kSTAFOk;}STAFRC_t recurseRemove(STAFFSEntryPtr entry, const STAFString &namePattern, const STAFString &extPattern, unsigned int entryTypesUInt, STAFFSCaseSensitive_t caseSensitive, STAFObjectPtr &outputList){ STAFFSEnumPtr childDirEnum = entry->enumerate(kUTF8_STAR, kUTF8_STAR, kSTAFFSDirectory); STAFRC_t rc = kSTAFOk; for (; childDirEnum->isValid(); childDirEnum->next()) { STAFFSEntryPtr childDirEntry = childDirEnum->entry(); // If child directory entry is a link, skip it if (!childDirEntry->isLink()) { rc = recurseRemove(childDirEntry, namePattern, extPattern, entryTypesUInt, caseSensitive, outputList); } } rc = removeChildren(entry, namePattern, extPattern, entryTypesUInt, caseSensitive, outputList); return kSTAFOk;}STAFRC_t addListDirectoryEntry( STAFString rootDir, STAFFSEntryPtr entry, STAFObjectPtr &outputList, STAFObjectPtr &mc, bool showLong, bool details){ // Remove the root directory from the name STAFString theName = entry->path().asString(); theName = theName.subString(rootDir.length() + 1); // Adds an entry in the specified format to the outputList. // Used when listing the contents of a directory.. if (showLong && details) { STAFObjectPtr fileInfoMap = fListDetailsInfoClass->createInstance(); fileInfoMap->put("name", theName); fileInfoMap->put("type", getTypeString(entry->type())); fileInfoMap->put("upperSize", STAFString(entry->size().first)); fileInfoMap->put("lowerSize", STAFString(entry->size().second)); fileInfoMap->put("lastModifiedTimestamp", entry->modTime().asString()); outputList->append(fileInfoMap); } else if (showLong && !details) { STAFObjectPtr fileInfoMap = fListLongInfoClass->createInstance(); fileInfoMap->put("type", getTypeString(entry->type())); STAFString sizeInfo; if (entry->size().first == 0) { if (entry->size().second > (99999 * 1024)) { sizeInfo = (entry->size().second / (1024 * 1024)); sizeInfo += "M"; } else if (entry->size().second > 99999) { sizeInfo = (entry->size().second / 1024); sizeInfo += "K"; } else sizeInfo = entry->size().second; } else sizeInfo = "*****"; // 5 is the maximum length of sizeInfo + 1 fileInfoMap->put("size", sizeInfo); fileInfoMap->put("lastModifiedTimestamp", entry->modTime().asString()); fileInfoMap->put("name", theName); outputList->append(fileInfoMap); } else { outputList->append(theName); } return kSTAFOk;}STAFRC_t recurseListDir( STAFFSEntryPtr dirEntry, const STAFString &namePattern, const STAFString &extPattern, unsigned int entryTypesUInt, STAFFSCaseSensitive_t caseSensitive, STAFFSSortBy_t sortBy, STAFFSEntryList &entryList){ // Enumerate all entries whose type matches one specified, as well as // enumerate all directory entries STAFFSEnumPtr dirEnum = dirEntry->enumerate( kUTF8_STAR, kUTF8_STAR, STAFFSEntryType_t(STAFFSEntryType_t(entryTypesUInt) | kSTAFFSDirectory), sortBy, caseSensitive); // Iterate through all the entriess for (; dirEnum->isValid(); dirEnum->next()) { STAFFSEntryPtr entry = dirEnum->entry(); // Check if name and extension (in the specifies case) and type // match the specified criteria if ((STAFFileSystem::matchesWildcards(entry->path().name(), namePattern, caseSensitive)) && (STAFFileSystem::matchesWildcards(entry->path().extension(), extPattern, caseSensitive)) && (entry->type() & STAFFSEntryType_t(entryTypesUInt))) { // This entries matches the specified criteria so add an entry // to the matching entry list entryList.push_back(entry); } // Check if entry is a directory, recursively check if any of it's // entries match the specified criteria if (entry->type() & kSTAFFSDirectory) { // Skip special directories . and .. if ((entry->path().name() == sPeriod) || (entry->path().name() == sDoublePeriod)) continue; recurseListDir(entry, namePattern, extPattern, entryTypesUInt, caseSensitive, sortBy, entryList); } } return kSTAFOk;}STAFServiceResult convertToHex(const char *buffer, unsigned int fileLength){ // Convert the buffer to a hex format STAFBuffer<char> hexBuffer(new char[fileLength * 2], STAFBuffer<char>::INIT, STAFBuffer<char>::ARRAY); for (unsigned int i = 0, j = 0; i < fileLength; i++) { hexBuffer[j++] = HEX_TABLE[(buffer[i] >> 4) & 0xF]; hexBuffer[j++] = HEX_TABLE[buffer[i] & 0xF]; } // Return new result in hex format return STAFServiceResult(kSTAFOk, STAFString(hexBuffer, fileLength * 2, STAFString::kUTF8));}STAFServiceResult convertLineEndings(const char *buffer, unsigned int fileLength, const STAFString &textFormat, const STAFString &orgMachine, bool isLocalRequest, bool testFlag){ // Convert the line ending characters in the buffer STAFString windowsLEChar = STAFString(kUTF8_CR) + STAFString(kUTF8_LF); STAFString unixLEChar = STAFString(kUTF8_LF); // Determine the new line ending character(s) to use STAFString newLEChar = STAFString(""); if (textFormat.toUpperCase() == "NATIVE") { if (!isLocalRequest) { // Try to get the line separator for the originating machine. // If VAR resolve request fails (probably due to insufficient // trust), default to target system's line separator. // XXX: In STAF V3.0, change to get the line separator from // information passed to the service. STAFResultPtr lineSepResult = gSTAFProcHandlePtr->submit( orgMachine, "VAR", "RESOLVE STRING " + STAFHandle::wrapData("{STAF/Config/Sep/Line}")); if (lineSepResult->rc == kSTAFOk) { // XXX: If the originating machine is running STAF v2.x, // using the new VAR resolve string syntax does not // return a 7 due to the parser assuming the rest of // the string should be the value, so it line separator // begins with "STRING " (which is NOT what we want). if (lineSepResult->result.find("STRING ") != 0) newLEChar = lineSepResult->result; else { // Try using the old VAR resolve syntax in case the // originating machine is running STAF v2.x. lineSepResult = gSTAFProcHandlePtr->submit( orgMachine, "VAR", "RESOLVE " + STAFHandle::wrapData("{STAF/Config/Sep/Line}")); if (lineSepResult->rc == kSTAFOk) newLEChar = lineSepResult->result; } } } if (newLEChar == STAFString("")) { // Get the line ending character(s) for the system where the // file resides. STAFConfigInfo configInfo; STAFString_t errorBufferT; unsigned int osRC = 0; if (STAFUtilGetConfigInfo(&configInfo, &errorBufferT, &osRC) != kSTAFOk) { return STAFServiceResult( kSTAFBaseOSError, STAFString(errorBufferT, STAFString::kShallow) + ", RC: " + osRC); } // Default to the target system's line separator if target // system is the same as the orginating system (e.g. is local) or // if can't get the originating system's line separator. newLEChar = configInfo.lineSeparator; } } else if (textFormat.toUpperCase() == "WINDOWS") newLEChar = windowsLEChar; else if (textFormat.toUpperCase() == "UNIX") newLEChar = unixLEChar; else newLEChar = textFormat; STAFString result = STAFString(buffer, fileLength); // Check which line endings the file actually contains and assign // to currLEChar. The first line-ending found for Windows (0D0A) // or Unix (0A) determines the line endings assumed for the file. // If no line-endings are found in the file, default to newLEChar // so that no line-endings conversion is done. STAFString currLEChar = newLEChar; unsigned int windowsLEIndex = result.find(windowsLEChar); unsigned int unixLEIndex = result.find(unixLEChar); if (windowsLEIndex < unixLEIndex) currLEChar = windowsLEChar; else if (unixLEIndex < windowsLEIndex) currLEChar = unixLEChar; // If debug flag is true, prints line ending characters in hex bool debug = false; if (debug) { cout << "currLEChar in Hex: "; const char *buffer = currLEChar.buffer(); for (unsigned int y = 0; y < currLEChar.length(); ++y) { unsigned int currChar = static_cast<unsigned char>(buffer[y]); if (currChar < 16) cout << "0"; cout << hex << currChar << dec << " "; } cout << endl << "newLEChar in Hex: "; buffer = newLEChar.buffer(); for (unsigned int i = 0; i < newLEChar.length(); ++i) { unsigned int currChar = static_cast<unsigned char>(buffer[i]); if (currChar < 16) cout << "0"; cout << hex << currChar << dec << " "; } cout << endl << endl; } // If conversion of line ending character(s) is needed, replace the
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -