Example #1
0
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;
}
Example #2
0
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;
}
Example #3
0
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());
	
}
Example #4
0
bool VFSNodeNameCallback::handleNextNode(const VFSNode& node) {
    VString nodeName;
    node.getName(nodeName);
    mNameList.push_back(nodeName);
    return true;
}
Example #5
0
// 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);
    }
}
bool VFSNodeIterateTestCallback::handleNextNode(const VFSNode& node) {
    VString nodeName;
    node.getName(nodeName);
    mNodeNames.push_back(nodeName);
    return true;
}