Ejemplo n.º 1
0
ReturnStatus
FileMetaDAO::getDir(const std::string &path, std::list<PDEntry> *pEntryList)
{
    assert(pEntryList);

    Channel* pDataChannel = ChannelManager::getInstance()->Mapping(m_BucketId);
	NameSpace *DataNS = pDataChannel->m_DataNS;

    int rt = 0;
    int error = 0;
    std::string entryName;
    Args st;

    rt = DataNS->OpenDir(path.c_str(), &st);

    if (false == st.valid) {
        error = errno;

        ERROR_LOG("path %s, opendir() error, %s.",
                  path.c_str(), strerror(errno));

        if (ENOTDIR == error) {
            return ReturnStatus(MU_FAILED, NOT_DIRECTORY);

        } else if (ENOENT == error) {
            return checkPrefix(path);
        }
    }

    Dirent dirent;

    while(DataNS->ReadDirNext(&st, &dirent)){
        entryName = dirent.filename;

        // omit "." and ".."
        // omit user info file in user root dir
        if (entryName == DENTRY_CURRENT_DIR
            || entryName == DENTRY_PARENT_DIR
            || entryName == USER_INFO_FILE_NAME) {
            continue;
        }

        PDEntry ent;
        ent.m_Name = entryName;

        if (MU_DIRECTORY == dirent.filetype) {
            ent.m_Type = MU_DIRECTORY;

        } else {
            ent.m_Type = MU_REGULAR_FILE;
        }

        pEntryList->push_back(ent);
    }


    return ReturnStatus(MU_SUCCESS);
}
Ejemplo n.º 2
0
ReturnStatus
FileMetaDAO::getDir2(const std::string &path,
                     std::list<EDEntry> *pEntryList)
{
    assert(pEntryList);

    Channel* pDataChannel = ChannelManager::getInstance()->Mapping(m_BucketId);
	NameSpace *DataNS = pDataChannel->m_DataNS;

    int rt = 0;
    int error = 0;
    std::string entryName;
    std::string npath;
	Args st;

    rt = DataNS->OpenDir(path.c_str(), &st);
    if (false == st.valid) {
        error = errno;

        ERROR_LOG("path %s, opendir() error, %s.",
                  path.c_str(), strerror(errno));

        if (ENOTDIR == error) {
            return ReturnStatus(MU_FAILED, NOT_DIRECTORY);

        } else if (ENOENT == error) {
            return checkPrefix(path);
        }
    }

    FileMeta meta;
    ReturnStatus rs;
    Dirent dirent;

    while(DataNS->ReadDirNext(&st, &dirent)){
        entryName = dirent.filetype;
        npath = path + PATH_SEPARATOR_STRING + entryName;

        // omit "." and ".."
        // omit user info file in user root dir
        if (entryName == DENTRY_CURRENT_DIR
            || entryName == DENTRY_PARENT_DIR
            || entryName == USER_INFO_FILE_NAME) {
            continue;
        }

        EDEntry ent;
        ent.m_Name = entryName;

        if (MU_DIRECTORY == dirent.filetype) {
            ent.m_Type = MU_DIRECTORY;

            rs = statDir(npath, &meta);

            if (!rs.success()) {
                ERROR_LOG("path %s, statDir() error", npath.c_str());
                return rs;
            }

            ent.m_Mode = meta.m_Attr.m_Mode;
            ent.m_CTime = meta.m_Attr.m_CTime;
            ent.m_MTime = meta.m_Attr.m_MTime;
            ent.m_Size = meta.m_Attr.m_Size;

        } else {
            // clear data of last entry
            meta.m_BlockList.clear();

            rs = getFile(npath, &meta);

            if (!rs.success()) {
                ERROR_LOG("path %s, getFile() error", npath.c_str());
                return rs;
            }

            ent.m_Mode = meta.m_Attr.m_Mode;
            ent.m_CTime = meta.m_Attr.m_CTime;
            ent.m_MTime = meta.m_Attr.m_MTime;
            ent.m_Size = meta.m_Attr.m_Size;
            ent.m_Version = meta.m_Attr.m_Version;
            ent.m_Type = meta.m_Attr.m_Type;

            ent.m_BlockList = meta.m_BlockList;
        }

        pEntryList->push_back(ent);
    }


    return ReturnStatus(MU_SUCCESS);
}
Ejemplo n.º 3
0
ReturnStatus
FileMetaDAO::rmdirRecursive(const std::string &path, uint64_t *pDelta)
{
	Channel* pDataChannel = ChannelManager::getInstance()->Mapping(m_BucketId);
	NameSpace *DataNS = pDataChannel->m_DataNS;
	
    int rt = 0;
    ReturnStatus rs;
    int error = 0;
    std::string entryName;
    std::string npath;
    Args st;

	rt = DataNS->OpenDir(path.c_str(), &st);
    if (rt < 0) {
        error = errno;

        ERROR_LOG("path %s, opendir() error, %s.",
                  path.c_str(), strerror(errno));

        if (ENOTDIR == error) {
            ERROR_LOG("path %s, opendir() error, no directory");
            return ReturnStatus(MU_FAILED, NOT_DIRECTORY);

        } else if (ENOENT == error) {
            return checkPrefix(path);
        }
    }

    // delete its children

    Dirent dirent;

    while(DataNS->ReadDirNext(&st, &dirent)){
        entryName = dirent.filename;

        // omit "." and ".."
        // omit user info file in user root dir
        if (entryName == DENTRY_CURRENT_DIR
            || entryName == DENTRY_PARENT_DIR
            || entryName == USER_INFO_FILE_NAME) {
            continue;
        }

        npath = path + PATH_SEPARATOR_STRING + entryName;

        if (MU_DIRECTORY == dirent.filetype) {
            // directory, call myself to delete it
            rs = rmdirRecursive(npath, pDelta);

            if (!rs.success()) {
                ERROR_LOG("path %s, rmdirRecursive() error", npath.c_str());
                return rs;
            }

        } else {
            // add file size to changed user quota
            addFileSizeToDelta(npath, pDelta);

            // delete it directly
            rt = DataNS->Unlink(npath.c_str());

            if (-1 == rt) {
                ERROR_LOG("path %s, unlink() error, %s.",
                          npath.c_str(), strerror(errno));
                return ReturnStatus(MU_FAILED, MU_UNKNOWN_ERROR);
            }
        }
    }


    // delete path

    // do not delete user root
    if (path.substr(path.length() - 1) == ROOT_PATH) {
        return ReturnStatus(MU_SUCCESS);
    }

    rt = DataNS->RmDir(path.c_str());

    if (-1 == rt) {
        ERROR_LOG("path %s, rmdir() error, %s.",
                  path.c_str(), strerror(errno));
        return ReturnStatus(MU_FAILED, MU_UNKNOWN_ERROR);
    }

    return ReturnStatus(MU_SUCCESS);
}