• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ VFSNode类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中VFSNode的典型用法代码示例。如果您正苦于以下问题:C++ VFSNode类的具体用法?C++ VFSNode怎么用?C++ VFSNode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了VFSNode类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: setName

void VFSNode::setName(const VString& name) {
    VFSNode parentNode;
    this->getParentNode(parentNode);

    VString newPath = parentNode.getChildPath(name);
    this->setPath(newPath);
}
开发者ID:trygve-isaacson,项目名称:code-vault,代码行数:7,代码来源:vfsnode.cpp


示例2: dest

bool VFSNodeCopyDirectoryCallback::handleNextNode(const VFSNode& source) {
    VFSNode dest(mDestDir, source.getName());
    if (source.isFile()) {
        VFSNode::copyFile(source, dest);
    } else if (mRecursive) {
        VFSNode::copyDirectory(source, dest, mRecursive);
    }
    
    return true;
}
开发者ID:trygve-isaacson,项目名称:code-vault,代码行数:10,代码来源:vfsnode.cpp


示例3: _testBinaryFileIO

void VFSNodeUnit::_testBinaryFileIO(const VString& seriesLabel, VFSNode& node, VAbstractFileStream& fileStream) {
    // This output line is just to mark which kind of file i/o we're doing:
    this->logStatus(seriesLabel);

    VBinaryIOStream io(fileStream);

    fileStream.openWrite();

    io.writeS8(1);
    io.writeU8(2);
    io.writeS16(3);
    io.writeU16(4);
    io.writeS32(5L);
    io.writeU32(6L);
    io.writeS64(CONST_S64(7));
    io.writeU64(CONST_U64(8));
    io.writeFloat(9.9f);
    io.writeDouble(3.1415926);
    io.writeBool(true);
    io.writeString("hello");
    io.flush();

    fileStream.close();

    VUNIT_ASSERT_TRUE_LABELED(node.size() != 0, "non-empty file");
    VUNIT_ASSERT_TRUE_LABELED(node.isFile(), "is file");
    VUNIT_ASSERT_FALSE_LABELED(node.isDirectory(), "is not directory");

    fileStream.openReadOnly();

    VUNIT_ASSERT_TRUE_LABELED(io.readS8() == 1, "S8 match");
    VUNIT_ASSERT_TRUE_LABELED(io.readU8() == 2, "U8 match");
    VUNIT_ASSERT_TRUE_LABELED(io.readS16() == 3, "S16 match");
    VUNIT_ASSERT_TRUE_LABELED(io.readU16() == 4, "U16 match");
    VUNIT_ASSERT_TRUE_LABELED(io.readS32() == 5L, "S32 match");
    VUNIT_ASSERT_TRUE_LABELED(io.readU32() == 6L, "U32 match");
    VUNIT_ASSERT_TRUE_LABELED(io.readS64() == CONST_S64(7), "S64 match");
    VUNIT_ASSERT_TRUE_LABELED(io.readU64() == CONST_U64(8), "U64 match");
    VUNIT_ASSERT_TRUE_LABELED(io.readFloat() == 9.9f, "Float match");
    VUNIT_ASSERT_TRUE_LABELED(io.readDouble() == 3.1415926, "Double match");
    VUNIT_ASSERT_TRUE_LABELED(io.readBool() == true, "Bool match");
    VUNIT_ASSERT_TRUE_LABELED(io.readString() == "hello", "String match");
    try {
        // We should not be able to read any more data.
        (void) io.readU8();
        // If we get here, there's junk past the proper end of the file.
        VUNIT_ASSERT_FAILURE("EOF mark position");
    } catch (const VEOFException& /*ex*/) {
        VUNIT_ASSERT_SUCCESS("EOF mark position");
    } catch (...) {
        VUNIT_ASSERT_FAILURE("EOF mark position (unexpected exception type)");
    }

    fileStream.close();
}
开发者ID:trygve-isaacson,项目名称:code-vault,代码行数:55,代码来源:vfsnodeunit.cpp


示例4: renameToName

void VFSNode::renameToName(const VString& newName, VFSNode& nodeToUpdate) const {
    VFSNode parentNode;
    this->getParentNode(parentNode);

    VString newPath;
    parentNode.getChildPath(newName, newPath);

    this->_platform_renameNode(newPath);

    nodeToUpdate.setPath(newPath);    // it IS allowed for nodeToUpdate to be this
}
开发者ID:trygve-isaacson,项目名称:code-vault,代码行数:11,代码来源:vfsnode.cpp


示例5: VUNIT_ASSERT_EQUAL_LABELED

void VFSNodeUnit::_testTextFileReadAll(VFSNode& node) {
    VString contents;
    node.readAll(contents);
    VUNIT_ASSERT_EQUAL_LABELED(contents, mTextFileContents, "VFSNode::readAll() to VString");

    VStringVector lines;
    node.readAll(lines);
    VUNIT_ASSERT_EQUAL_LABELED((int) lines.size(), (int) mTextFileLines.size(), "VFSNode::readAll() to VStringVector, count");

    int lineNumber = 1;
    for (size_t i = 0; i < lines.size(); ++i) {
        VUNIT_ASSERT_EQUAL_LABELED(lines[i], mTextFileLines[i], VSTRING_FORMAT("VFSNode::readAll() to VStringVector, line %d match", lineNumber));
        ++lineNumber;
    }
}
开发者ID:trygve-isaacson,项目名称:code-vault,代码行数:15,代码来源:vfsnodeunit.cpp


示例6: mkdirs

void VFSNode::mkdirs() const {
    // If this directory already exists, we are done.
    if (this->exists())
        return;

    // Create the parent directory (and its parents etc.) if necessary.
    VFSNode    parentNode;
    this->getParentNode(parentNode);

    if (! parentNode.getPath().isEmpty())    // root or parent of supplied path must be assumed to exist
        parentNode.mkdirs();

    // Create this directory specifically.
    this->mkdir();
}
开发者ID:trygve-isaacson,项目名称:code-vault,代码行数:15,代码来源:vfsnode.cpp


示例7:

VFSDir::VFSDir(VFSNode *parentnode, char *name)
{
	m_ParentNode = parentnode;
	m_Name 	= name;
	m_Type = VFS_DIR;
	VFSNode *parent = m_ParentNode;
	string path = name;
	while (parent != NULL)
	{
		path = "\\" + path;
		path = parent->getName() + path;
		parent = parent->getParent();
	}
	logSpam(" created dir %s \n",path.c_str());
	
}
开发者ID:jrwren,项目名称:nepenthes,代码行数:16,代码来源:VFSDir.cpp


示例8: _writeKnownDirectoryTestFile

void VFSNodeUnit::_writeKnownDirectoryTestFile(VFSNode::KnownDirectoryIdentifier id, const VString& fileName) {
    VFSNode folder = VFSNode::getKnownDirectoryNode(id, "BombayDigital", "unittest-temp");

    VFSNode fileNode;
    folder.getChildNode(fileName, fileNode);

    VBufferedFileStream fs(fileNode);
    fs.openWrite();

    VTextIOStream out(fs);

    VInstant now;
    out.writeLine(now.getLocalString());
    out.flush();

    this->logStatus(VSTRING_FORMAT("Wrote to file '%s'.", fileNode.getPath().chars()));
}
开发者ID:trygve-isaacson,项目名称:code-vault,代码行数:17,代码来源:vfsnodeunit.cpp


示例9: _testTextFileIO

void VFSNodeUnit::_testTextFileIO(const VString& seriesLabel, VFSNode& node, VAbstractFileStream& fileStream) {
    // This output line is just to mark which kind of file i/o we're doing:
    this->logStatus(seriesLabel);

    VTextIOStream io(fileStream);
    fileStream.openWrite();

    for (VStringVector::const_iterator i = mTextFileLines.begin(); i != mTextFileLines.end(); ++i)
        io.writeLine(*i);

    io.flush();

    fileStream.close();

    VUNIT_ASSERT_TRUE_LABELED(node.size() != 0, "non-empty file");
    VUNIT_ASSERT_TRUE_LABELED(node.isFile(), "is file");
    VUNIT_ASSERT_FALSE_LABELED(node.isDirectory(), "is not directory");

    fileStream.openReadOnly();

    VString line;
    int lineNumber = 1;
    for (VStringVector::const_iterator i = mTextFileLines.begin(); i != mTextFileLines.end(); ++i) {
        io.readLine(line);
        VUNIT_ASSERT_EQUAL_LABELED(line, *i, VSTRING_FORMAT("Line %d match", lineNumber));
        ++lineNumber;
    }

    try {
        // We should not be able to read any more lines.
        io.readLine(line);
        // If we get here, there's junk past the proper end of the file.
        VUNIT_ASSERT_FAILURE("EOF mark position");
    } catch (const VEOFException& /*ex*/) {
        VUNIT_ASSERT_SUCCESS("EOF mark position");
    } catch (...) {
        VUNIT_ASSERT_FAILURE("EOF mark position (unexpected exception type)");
    }

    fileStream.close();
}
开发者ID:trygve-isaacson,项目名称:code-vault,代码行数:41,代码来源:vfsnodeunit.cpp


示例10: handleNextNode

bool VFSNodeFindCallback::handleNextNode(const VFSNode& node) {
    VString nodeNameLowerCase;
    node.getName(nodeNameLowerCase);
    nodeNameLowerCase.toLowerCase();

    if (nodeNameLowerCase == mNameToMatchLowerCase) {
        mFound = true;
        mMatchedNode = node;
        return false; // we found a match, so stop looking
    }

    return true;
}
开发者ID:trygve-isaacson,项目名称:code-vault,代码行数:13,代码来源:vfsnode.cpp


示例11: VException

// static
void VFSNode::copyDirectory(const VFSNode& source, const VFSNode& dest, bool recursive) {
    if (recursive) {
        VString sourcePathWithTrailingSeparator = source.getPath() + (source.getPath().endsWith(PATH_SEPARATOR_CHAR) ? "" : PATH_SEPARATOR_CHARS);
        if (dest.getPath().startsWith(sourcePathWithTrailingSeparator)) {
            throw VException(VSTRING_FORMAT("Attempt to recursively copy '%s' into '%s'.", source.getPath().chars(), dest.getPath().chars()));
        }
    }

    if (!dest.exists()) {
        dest.mkdirs();
    }
    
    VFSNodeCopyDirectoryCallback copyDirectoryCallback(dest, recursive);
    source.iterate(copyDirectoryCallback);
}
开发者ID:trygve-isaacson,项目名称:code-vault,代码行数:16,代码来源:vfsnode.cpp


示例12: VFSNode

// static
VFSNode VFSNode::_platform_getKnownDirectoryNode(KnownDirectoryIdentifier id, const VString& companyName, const VString& appName) {
    if (id == CURRENT_WORKING_DIRECTORY) {
        return VFSNode(VPlatformAPI::getcwd());
    }

    if (id == EXECUTABLE_DIRECTORY) {
        /*
        This depends on the structure of the application or tool.
        If it's an iOS application, it's a bundle where we have:
            /...../wanted-dir/AppName.app/executable
            (2 levels up, wanted-dir is a randomized serial number at some path)
        If it's built as a Mac OS X application bundle we have:
            /...../wanted-dir/AppName.app/Contents/MacOS/executable
            (4 levels up, typically wanted-dir is /Applications if installed, but doesn't have to be)
        If it's built as a simple Unix-y tool we have:
            /...../wanted-dir/executable
            (1 level up, wanted-dir is wherever the tool has been placed)
        */
#ifdef VPLATFORM_MAC_IOS
        const int NUM_LEVELS_UP = 2;
#else
#ifdef VAULT_MACOSX_APP_IS_BUNDLE
        const int NUM_LEVELS_UP = 4;
#else
        const int NUM_LEVELS_UP = 1;
#endif
#endif
        VFSNode node = VFSNode::getExecutable();
        for (int i = 0; i < NUM_LEVELS_UP; ++i) {
            VFSNode parentNode;
            node.getParentNode(parentNode);
            node = parentNode;
        }

        return node;
    }

    VFSNode currentUserFolder(_V_NSHomeDirectory());

    if (id == USER_HOME_DIRECTORY) {
        return currentUserFolder;
    }

    VFSNode libraryFolder;
    currentUserFolder.getChildNode("Library", libraryFolder);
    libraryFolder.mkdir();

    VFSNode subFolder;

    switch (id) {
        case USER_HOME_DIRECTORY:
            // handled earlier; we returned above
            break;

        case LOG_FILES_DIRECTORY:
            libraryFolder.getChildNode("Logs", subFolder);
            break;

        case USER_PREFERENCES_DIRECTORY:
            libraryFolder.getChildNode("Preferences", subFolder);
            break;

        case CACHED_DATA_DIRECTORY:
            libraryFolder.getChildNode("Caches", subFolder);
            break;

        case APPLICATION_DATA_DIRECTORY:
            subFolder = libraryFolder;
            break;

        case CURRENT_WORKING_DIRECTORY:
            // handled earlier; we returned above
            break;

        case EXECUTABLE_DIRECTORY:
            // handled earlier; we returned above
            break;

        default:
            throw VStackTraceException(VSTRING_FORMAT("VFSNode::_platform_getKnownDirectoryNode: Requested invalid directory ID %d.", (int) id));
            break;
    }

    subFolder.mkdir();

    VFSNode companyFolder;
    if (companyName.isEmpty()) {
        companyFolder = subFolder;
    } else {
        subFolder.getChildNode(companyName, companyFolder);
        companyFolder.mkdir();
    }

    VFSNode resultNode;
    if (appName.isEmpty()) {
        resultNode = companyFolder;
    } else {
        companyFolder.getChildNode(appName, resultNode);
        resultNode.mkdir();
//.........这里部分代码省略.........
开发者ID:JohnChristman,项目名称:code-vault,代码行数:101,代码来源:vfsnode_platform.cpp


示例13: renameToNode

void VFSNode::renameToNode(const VFSNode& newNode) const {
    VString newPath;
    newNode.getPath(newPath);

    this->_platform_renameNode(newPath);
}
开发者ID:trygve-isaacson,项目名称:code-vault,代码行数:6,代码来源:vfsnode.cpp


示例14: testIterFileName

void VFSNodeUnit::_testDirectoryIteration(const VFSNode& dir) {
    const int NUM_FILES_TO_CREATE = 5;
    const int NUM_FILES_TO_CHECK = NUM_FILES_TO_CREATE + 3; // we'll verify we don't have these extras

    // Test directory listing, iteration, find.
    // Create 5 files in the deep directory, then test that we can find them.
    for (int i = 0; i < NUM_FILES_TO_CREATE; ++i) {
        VString testIterFileName(VSTRING_ARGS("iter_test_%d.txt", i));
        VFSNode testIterFileNode;
        dir.getChildNode(testIterFileName, testIterFileNode);
        VBufferedFileStream testIterStream(testIterFileNode);
        testIterStream.openWrite();
        VTextIOStream out(testIterStream);
        out.writeLine(testIterFileName);
    }

    {
        // find() test
        VFSNode testIterNode;
        for (int i = 0; i < NUM_FILES_TO_CHECK; ++i) {
            VString testIterFileName(VSTRING_ARGS("iter_test_%d.txt", i));
            if (i < NUM_FILES_TO_CREATE)
                VUNIT_ASSERT_TRUE_LABELED(dir.find(testIterFileName, testIterNode), VSTRING_FORMAT("find() found #%d", i)); // this file should exist
            else
                VUNIT_ASSERT_FALSE_LABELED(dir.find(testIterFileName, testIterNode), VSTRING_FORMAT("find() did not find #%d", i)); // this file should not exist
        }
    }

    // There is no guarantee that the list() and iterate() methods will return the directory
    // listing in any particular order. We either need to sort them ourself, or verify without
    // regard to order. Here, we'll sort the returned string list, since we know that our
    // file names are sortable because they are single-digit-number-based strings, e.g. "iter_test_3.txt".
    // Note that the result of sorting is ultimately dependent on strcmp().

    {
        // list() names test
        int index = 0;
        VStringVector fileNames;
        dir.list(fileNames);
        std::sort(fileNames.begin(), fileNames.end());
        VUNIT_ASSERT_EQUAL_LABELED(static_cast<int>(fileNames.size()), NUM_FILES_TO_CREATE, "list names size");
        for (VStringVector::const_iterator i = fileNames.begin(); i != fileNames.end(); ++i, ++index) {
            VString testIterFileName(VSTRING_ARGS("iter_test_%d.txt", index));
            VUNIT_ASSERT_EQUAL_LABELED(*i, testIterFileName, VSTRING_FORMAT("list names #%d", index));
        }
    }

    {
        // list() nodes test
        int index = 0;
        VFSNodeVector fileNodes;
        dir.list(fileNodes);
        std::sort(fileNodes.begin(), fileNodes.end());
        VUNIT_ASSERT_EQUAL_LABELED(static_cast<int>(fileNodes.size()), NUM_FILES_TO_CREATE, "list nodes size");
        for (VFSNodeVector::const_iterator i = fileNodes.begin(); i != fileNodes.end(); ++i, ++index) {
            VString testIterFileName(VSTRING_ARGS("iter_test_%d.txt", index));
            VString nodeFileName;
            i->getName(nodeFileName);
            VUNIT_ASSERT_EQUAL_LABELED(nodeFileName, testIterFileName, VSTRING_FORMAT("list nodes #%d", index));
        }
    }

    {
        // iterate() test
        int index = 0;
        VFSNodeIterateTestCallback callback;
        dir.iterate(callback);
        std::sort(callback.mNodeNames.begin(), callback.mNodeNames.end());
        VUNIT_ASSERT_EQUAL_LABELED(static_cast<int>(callback.mNodeNames.size()), NUM_FILES_TO_CREATE, "iterate size");
        for (VStringVector::const_iterator i = callback.mNodeNames.begin(); i != callback.mNodeNames.end(); ++i, ++index) {
            VString testIterFileName(VSTRING_ARGS("iter_test_%d.txt", index));
            VUNIT_ASSERT_EQUAL_LABELED(*i, testIterFileName, VSTRING_FORMAT("iterate nodes #%d", index));
        }
    }

}
开发者ID:trygve-isaacson,项目名称:code-vault,代码行数:76,代码来源:vfsnodeunit.cpp


示例15: handleNextNode

bool VFSNodeIterateTestCallback::handleNextNode(const VFSNode& node) {
    VString nodeName;
    node.getName(nodeName);
    mNodeNames.push_back(nodeName);
    return true;
}
开发者ID:trygve-isaacson,项目名称:code-vault,代码行数:6,代码来源:vfsnodeunit.cpp


示例16: getChildNode

void VFSNode::getChildNode(const VString& childName, VFSNode& child) const {
    VString childPath;

    this->getChildPath(childName, childPath);
    child.setPath(childPath);
}
开发者ID:trygve-isaacson,项目名称:code-vault,代码行数:6,代码来源:vfsnode.cpp


示例17: getParentNode

void VFSNode::getParentNode(VFSNode& parent) const {
    VString parentPath;

    this->getParentPath(parentPath);
    parent.setPath(parentPath);
}
开发者ID:trygve-isaacson,项目名称:code-vault,代码行数:6,代码来源:vfsnode.cpp


示例18: testDirRoot

void VFSNodeUnit::run() {
    // Note that we also do testing of streams and file i/o here.

    this->logStatus(VSTRING_FORMAT("getExecutable: '%s'", VFSNode::getExecutable().getPath().chars()));
    this->logStatus(VSTRING_FORMAT("getExecutableDirectory: '%s'", VFSNode::getExecutableDirectory().getPath().chars()));
    this->logStatus(VSTRING_FORMAT("USER_HOME_DIRECTORY: '%s'", VFSNode::getKnownDirectoryNode(VFSNode::USER_HOME_DIRECTORY, "com", "app").getPath().chars()));
    this->logStatus(VSTRING_FORMAT("LOG_FILES_DIRECTORY: '%s'", VFSNode::getKnownDirectoryNode(VFSNode::LOG_FILES_DIRECTORY, "com", "app").getPath().chars()));
    this->logStatus(VSTRING_FORMAT("USER_PREFERENCES_DIRECTORY: '%s'", VFSNode::getKnownDirectoryNode(VFSNode::USER_PREFERENCES_DIRECTORY, "com", "app").getPath().chars()));
    this->logStatus(VSTRING_FORMAT("CACHED_DATA_DIRECTORY: '%s'", VFSNode::getKnownDirectoryNode(VFSNode::CACHED_DATA_DIRECTORY, "com", "app").getPath().chars()));
    this->logStatus(VSTRING_FORMAT("APPLICATION_DATA_DIRECTORY: '%s'", VFSNode::getKnownDirectoryNode(VFSNode::APPLICATION_DATA_DIRECTORY, "com", "app").getPath().chars()));
    this->logStatus(VSTRING_FORMAT("CURRENT_WORKING_DIRECTORY: '%s'", VFSNode::getKnownDirectoryNode(VFSNode::CURRENT_WORKING_DIRECTORY, "com", "app").getPath().chars()));
    this->logStatus(VSTRING_FORMAT("EXECUTABLE_DIRECTORY: '%s'", VFSNode::getKnownDirectoryNode(VFSNode::EXECUTABLE_DIRECTORY, "com", "app").getPath().chars()));

    VFSNode tempDir = VFSNode::getKnownDirectoryNode(VFSNode::CACHED_DATA_DIRECTORY, "vault", "unittest");
    VString tempDirPath = tempDir.getPath();

    VFSNode testDirRoot(tempDir, "vfsnodetest_temp");
    (void) testDirRoot.rm();

    VFSNode testDirDeep(tempDir, "vfsnodetest_temp/one/two/three");
    VUNIT_ASSERT_FALSE_LABELED(testDirDeep.exists(), "initial state 1");
    testDirDeep.mkdirs();
    VUNIT_ASSERT_TRUE_LABELED(testDirDeep.exists(), "deep mkdirs");

    VFSNode testDirDeeper(testDirDeep, "four");
    VUNIT_ASSERT_FALSE_LABELED(testDirDeeper.exists(), "initial state 2");
    testDirDeeper.mkdirs();
    VUNIT_ASSERT_TRUE_LABELED(testDirDeeper.exists(), "one-deep mkdirs");

    // Now that we have created a deep directory structure, let's do some
    // file i/o streams stuff here.

    VFSNode testTextFileNode(testDirDeeper, "test_text_file.txt");

    VBufferedFileStream btfs(testTextFileNode);
    this->_testTextFileIO("starting Buffered Text IO tests", testTextFileNode, btfs);
    (void) testTextFileNode.rm();
    VUNIT_ASSERT_FALSE_LABELED(testTextFileNode.exists(), "buffered text file removed");

    VDirectIOFileStream dtfs(testTextFileNode);
    this->_testTextFileIO("starting Unbuffered Text IO tests", testTextFileNode, dtfs);
    this->_testTextFileReadAll(testTextFileNode);
    (void) testTextFileNode.rm();
    VUNIT_ASSERT_FALSE_LABELED(testTextFileNode.exists(), "unbuffered text file removed");

    VFSNode testBinaryFileNode(testDirDeeper, "test_binary_file");

    VBufferedFileStream bbfs(testBinaryFileNode);
    this->_testBinaryFileIO("starting Buffered Binary IO tests", testBinaryFileNode, bbfs);
    (void) testBinaryFileNode.rm();
    VUNIT_ASSERT_FALSE_LABELED(testBinaryFileNode.exists(), "buffered binary file removed");

    VDirectIOFileStream dbfs(testBinaryFileNode);
    this->_testBinaryFileIO("starting Unbuffered Binary IO tests", testBinaryFileNode, dbfs);
    (void) testBinaryFileNode.rm();
    VUNIT_ASSERT_FALSE_LABELED(testBinaryFileNode.exists(), "unbuffered binary file removed");

    this->_testDirectoryIteration(testDirDeeper);

    // Next, test all flavors of renaming operations.
    VFSNode copyTest1(tempDir, "vfsnodetest_temp/one/two/test1.txt");
    VBufferedFileStream sourceFileStream(copyTest1);
    sourceFileStream.openWrite();
    VTextIOStream sourceOut(sourceFileStream);
    sourceOut.writeLine("line 1");
    sourceOut.writeLine("line 2");
    sourceOut.flush();
    sourceFileStream.close();
    VUNIT_ASSERT_TRUE_LABELED(copyTest1.exists(), "test1 exists");

    VFSNode copyTest2(tempDir, "vfsnodetest_temp/one/two/test2.txt");
    copyTest1.renameToName("test2.txt");
    VUNIT_ASSERT_FALSE_LABELED(copyTest1.exists(), "test1 was renamed");
    VUNIT_ASSERT_TRUE_LABELED(copyTest2.exists(), "test2 exists");

    VFSNode copyTest3;
    copyTest2.renameToName("test3.txt", copyTest3);
    VUNIT_ASSERT_FALSE_LABELED(copyTest2.exists(), "test2 was renamed");
    VUNIT_ASSERT_TRUE_LABELED(copyTest3.getPath() == tempDirPath + "/vfsnodetest_temp/one/two/test3.txt" && copyTest3.exists(), "test3 exists");

    VFSNode copyTest4(tempDir, "vfsnodetest_temp/one/two/three/test4.txt");
    copyTest3.renameToNode(copyTest4);
    VUNIT_ASSERT_FALSE_LABELED(copyTest3.exists(), "test3 was moved and renamed");
    VUNIT_ASSERT_TRUE_LABELED(copyTest4.exists(), "test4 exists");

    copyTest4.renameToPath(tempDirPath + "/vfsnodetest_temp/one/two/test5.txt");
    VFSNode copyTest5(tempDir, "vfsnodetest_temp/one/two/test5.txt");
    VUNIT_ASSERT_FALSE_LABELED(copyTest4.exists(), "test4 was moved and renamed");
    VUNIT_ASSERT_TRUE_LABELED(copyTest5.exists(), "test5 exists");

    copyTest5.renameToName("test5.txt"); // should throw
    
    VFSNode dirCopyTarget(tempDir, "vfsnodetest_temp_copy");
    VFSNode::copyDirectory(testDirRoot, dirCopyTarget, true);
    // Verify that expected files now exist. Very dependent on file operations performed in tests above.
    VUNIT_ASSERT_TRUE_LABELED(VFSNode(tempDirPath + "/vfsnodetest_temp_copy/one/two/test5.txt").isFile(), "copied directory, spot check test5.txt");
    VUNIT_ASSERT_TRUE_LABELED(VFSNode(tempDirPath + "/vfsnodetest_temp_copy/one/two/three/four/iter_test_0.txt").isFile(), "copied directory, spot check iter_test_0.txt");
    VUNIT_ASSERT_TRUE_LABELED(VFSNode(tempDirPath + "/vfsnodetest_temp_copy/one/two/three/four/iter_test_1.txt").isFile(), "copied directory, spot check iter_test_1.txt");
    VUNIT_ASSERT_TRUE_LABELED(VFSNode(tempDirPath + "/vfsnodetest_temp_copy/one/two/three/four/iter_test_2.txt").isFile(), "copied directory, spot check iter_test_2.txt");
    VUNIT_ASSERT_TRUE_LABELED(VFSNode(tempDirPath + "/vfsnodetest_temp_copy/one/two/three/four/iter_test_3.txt").isFile(), "copied directory, spot check iter_test_3.txt");
//.........这里部分代码省略.........
开发者ID:trygve-isaacson,项目名称:code-vault,代码行数:101,代码来源:vfsnodeunit.cpp


示例19: mPath

VFSNode::VFSNode(const VFSNode& directory, const VString& childName)
    : mPath()
    {
    directory.getChildNode(childName, *this);
}
开发者ID:trygve-isaacson,项目名称:code-vault,代码行数:5,代码来源:vfsnode.cpp


示例20: originalTargetNode

// static
void VFSNode::safelyOverwriteFile(const VFSNode& target, Vs64 dataLength, VBinaryIOStream& dataStream, bool keepOld) {
    bool success = true;
    VString errorMessage;

    VString targetFileName = target.getName();

    VInstant now;
    VString temporaryFileName = now.getLocalString(VFSNODE_SAFE_FILE_NAME_INSTANT_FORMATTER) + "_tmp_" + targetFileName;
    VString keptFileName = now.getLocalString(VFSNODE_SAFE_FILE_NAME_INSTANT_FORMATTER) + "_ver_" + targetFileName;

    VFSNode directoryNode;
    target.getParentNode(directoryNode);
    VFSNode originalTargetNode(target);
    VFSNode temporaryFileNode(directoryNode, temporaryFileName);
    VFSNode keptFileNode(directoryNode, keptFileName);

    // Create and write to the temp file within a scope block to ensure file is closed when scope is exited.
    /* stream scope */ {
        VBufferedFileStream tempFileStream(temporaryFileNode);
        VBinaryIOStream tempOutputStream(tempFileStream);

        try {
            tempFileStream.openWrite();
        } catch (const VException& ex) {
            success = false;
            errorMessage = VSTRING_FORMAT("Unable to open temporary file '%s': %s", target.getPath().chars(), ex.what());
        }

        if (success) {
            try {
                VStream::streamCopy(dataStream, tempOutputStream, dataLength);
                tempOutputStream.flush();
            } catch (const VException& ex) {
                success = false;
                errorMessage = VSTRING_FORMAT("Unable to write to temporary file '%s': %s", target.getPath().chars(), ex.what());
            }
        }
    }

    /*
    If we succeeded, delete or rename the original file, and rename the temporary file to the original location.
    If we failed, delete the temporary file.
    Do this itself in separate phases, so that if the delete/rename fails, we still delete the temporary file.
    */
    // 1. Remove target. (It might not exist yet.)
    if (success && target.exists()) {
    
        if (keepOld) {
        
            try {
                target.renameToNode(keptFileNode);
            } catch (const VException& ex) {
                success = false;
                errorMessage = VSTRING_FORMAT("Failed renaming '%s' to '%s': %s", target.getPath().chars(), keptFileNode.getPath().chars(), ex.what());
            }

        } else {

            if (! target.rm()) {
                success = false;
                errorMessage = VSTRING_FORMAT("Unable to remove target file '%s'.", target.getPath().chars());
            }

        }
    
    }

    // 2. Rename temporary to (original) target.
    if (success) {
        try {
            temporaryFileNode.renameToNode(originalTargetNode);
        } catch (const VException& ex) {
            success = false;
            errorMessage = VSTRING_FORMAT("Failed renaming '%s' to '%s': %s", temporaryFileNode.getPath().chars(), originalTargetNode.getPath().chars(), ex.what());
        }
    }

    // 3. Remove temporary if unsuccessful.
    if (! success) {
        if (! temporaryFileNode.rm()) {
            errorMessage += VSTRING_FORMAT(" Removal of temporary file '%s' failed.", temporaryFileNode.getPath().chars());
        }
    }

    // If we failed, throw an exception with the error message we built wherever we encountered errors.
    if (! success) {
        throw VException(errorMessage);
    }
}
开发者ID:trygve-isaacson,项目名称:code-vault,代码行数:90,代码来源:vfsnode.cpp



注:本文中的VFSNode类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ VFile类代码示例发布时间:2022-05-31
下一篇:
C++ VFKReaderSQLite类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap