示例#1
0
文件: TeaSafe.cpp 项目: iwpiv/teasafe
    void
    TeaSafe::renameEntry(std::string const &src, std::string const &dst)
    {
        StateLock lock(m_stateMutex);
        std::string srcPath(src);
        char ch = *src.rbegin();
        // ignore trailing slash
        if (ch == '/') {
            std::string(src.begin(), src.end() - 1).swap(srcPath);
        }
        std::string dstPath(dst);
        char chDst = *dst.rbegin();
        // ignore trailing slash
        if (chDst == '/') {
            std::string(dst.begin(), dst.end() - 1).swap(dstPath);
        }

        // throw if source parent doesn't exist
        SharedTeaSafeFolder parentSrc = doGetParentTeaSafeFolder(srcPath);
        if (!parentSrc) {
            throw TeaSafeException(TeaSafeError::NotFound);
        }

        // throw if destination parent doesn't exist
        SharedTeaSafeFolder parentDst = doGetParentTeaSafeFolder(dstPath);
        if (!parentSrc) {
            throw TeaSafeException(TeaSafeError::NotFound);
        }

        // throw if destination already exists
        throwIfAlreadyExists(dstPath);

        // throw if source doesn't exist
        std::string const filename = boost::filesystem::path(srcPath).filename().string();
        SharedEntryInfo childInfo = parentSrc->getEntryInfo(filename);
        if (!childInfo) {
            throw TeaSafeException(TeaSafeError::NotFound);
        }

        // do moving / renaming
        // (i) Remove original entry metadata entry
        // (ii) Add new metadata entry with new file name
        parentSrc->putMetaDataOutOfUse(filename);
        std::string dstFilename = boost::filesystem::path(dstPath).filename().string();
        parentDst->writeNewMetaDataForEntry(dstFilename, childInfo->type(), childInfo->firstFileBlock());

    }
示例#2
0
文件: TeaSafe.cpp 项目: iwpiv/teasafe
    void
    TeaSafe::addFolder(std::string const &path) const
    {
        StateLock lock(m_stateMutex);
        std::string thePath(path);
        char ch = *path.rbegin();
        // ignore trailing slash
        if (ch == '/') {
            std::string(path.begin(), path.end() - 1).swap(thePath);
        }

        SharedTeaSafeFolder parentEntry = doGetParentTeaSafeFolder(thePath);
        if (!parentEntry) {
            throw TeaSafeException(TeaSafeError::NotFound);
        }

        // throw if already exists
        throwIfAlreadyExists(path);

        parentEntry->addTeaSafeFolder(boost::filesystem::path(thePath).filename().string());
    }
示例#3
0
文件: TeaSafe.cpp 项目: iwpiv/teasafe
    void
    TeaSafe::addFile(std::string const &path)
    {
        StateLock lock(m_stateMutex);
        std::string thePath(path);
        char ch = *path.rbegin();
        // file entries with trailing slash should throw
        if (ch == '/') {
            throw TeaSafeException(TeaSafeError::IllegalFilename);
        }

        SharedTeaSafeFolder parentEntry = doGetParentTeaSafeFolder(thePath);
        if (!parentEntry) {
            throw TeaSafeException(TeaSafeError::NotFound);
        }

        // throw if already exists
        throwIfAlreadyExists(path);

        parentEntry->addTeaSafeFile(boost::filesystem::path(thePath).filename().string());
    }
示例#4
0
    void
    CoreFS::addFile(std::string const &path)
    {
        StateLock lock(m_stateMutex);
        auto thePath(path);
        char ch = *path.rbegin();
        // file entries with trailing slash should throw
        if (ch == '/') {
            throw KnoxCryptException(KnoxCryptError::IllegalFilename);
        }

        auto parentEntry(doGetParentCompoundFolder(thePath));

        if (!parentEntry) {
            throw KnoxCryptException(KnoxCryptError::NotFound);
        }

        // throw if already exists
        throwIfAlreadyExists(path);

        parentEntry->addFile(boost::filesystem::path(thePath).filename().string());
    }
示例#5
0
    void
    CoreFS::addFolder(std::string const &path) const
    {
        StateLock lock(m_stateMutex);
        auto thePath(path);
        char ch = *path.rbegin();
        // ignore trailing slash
        if (ch == '/') {
            std::string(path.begin(), path.end() - 1).swap(thePath);
        }

        auto parentEntry(doGetParentCompoundFolder(thePath));
        if (!parentEntry) {
            throw KnoxCryptException(KnoxCryptError::NotFound);
        }

        // throw if already exists
        throwIfAlreadyExists(path);

        parentEntry->addFolder(boost::filesystem::path(thePath).filename().string());

        parentEntry->getCompoundFolder()->getStream()->close();
    }
示例#6
0
    void
    CoreFS::renameEntry(std::string const &src, std::string const &dst)
    {
        StateLock lock(m_stateMutex);
        auto srcPath(src);
        char ch = *src.rbegin();
        // ignore trailing slash
        if (ch == '/') {
            std::string(src.begin(), src.end() - 1).swap(srcPath);
        }
        auto dstPath(dst);
        char chDst = *dst.rbegin();
        // ignore trailing slash
        if (chDst == '/') {
            std::string(dst.begin(), dst.end() - 1).swap(dstPath);
        }

        // throw if source parent doesn't exist
        auto parentSrc(doGetParentCompoundFolder(srcPath));
        if (!parentSrc) {
            throw KnoxCryptException(KnoxCryptError::NotFound);
        }

        // throw if destination parent doesn't exist
        auto parentDst(doGetParentCompoundFolder(dstPath));
        if (!parentSrc) {
            throw KnoxCryptException(KnoxCryptError::NotFound);
        }

        // throw if destination already exists
        throwIfAlreadyExists(dstPath);

        // throw if source doesn't exist
        auto const srcPathBoost = ::boost::filesystem::path(srcPath);
        auto const filename(srcPathBoost.filename().string());
        auto childInfo(parentSrc->getEntryInfo(filename));
        if (!childInfo) {
            throw KnoxCryptException(KnoxCryptError::NotFound);
        }

        // do moving / renaming
        // (i) Remove original entry metadata entry
        // (ii) Add new metadata entry with new file name
        // NOTE: As an optimization, if entry is to be moved to
        // same parent folder, don't bother invalidating parent metadata,
        // just update the name.
        auto const dstPathBoost = ::boost::filesystem::path(dstPath);
        auto const destPathParent(dstPathBoost.parent_path());
        auto const srcPathParent(srcPathBoost.parent_path());
        auto dstFilename(dstPathBoost.filename().string());

        if(destPathParent == srcPathParent) {
            parentSrc->updateMetaDataWithNewFilename(filename, dstFilename);
        } else {
            parentSrc->putMetaDataOutOfUse(filename);
            parentDst->writeNewMetaDataForEntry(dstFilename, childInfo->type(), childInfo->firstFileBlock());
        }

        // Need to remove parent entry from cache
        this->removeFolderFromCache(srcPathParent);

        // Also need to remove src from cache if folder
        if(childInfo->type() == EntryType::FolderType) {
            this->removeFolderFromCache(srcPath);
        }

        // need to also walk over children??

        // need to also check if this now f***s up the cached file
        resetCachedFile(srcPathBoost);
    }