Esempio n. 1
0
int 
plfs_opendir_c(const char *path, Plfs_dirp **pdirp) {
    debug_enter(__FUNCTION__,path);
    plfs_dir *pdir = new plfs_dir;
    *pdirp = (Plfs_dirp *)pdir;
    int ret = plfs_readdir(path, (void*)&(pdir->entries));
    if (ret != 0) {
        delete pdir;
        *pdirp = NULL;
    } else {
        pdir->itr = pdir->entries.begin();
        pdir->path = path;
    }
    debug_exit(__FUNCTION__,path,ret);
    return ret;
}
Esempio n. 2
0
void
PlfsUnit::dirTest() {
    string path = mountpoint + "/dirtest1";
    const char *pathname = path.c_str();
    set<string> dents;
    set<string> readres;
    set<string>::iterator it;
    plfs_error_t ret;

    ret = plfs_mkdir(pathname, PLFSUNIT_DEFAULT_DIR_MODE);
    CPPUNIT_ASSERT_EQUAL(0, (int)ret);
    for (int i = 0; i < 100; i++) {
	string subdir = generateRandomString();
	pair<set<string>::iterator, bool> result;
	result = dents.insert(subdir);
	if (result.second) {
	    string fullpath = path + subdir;
	    ret = plfs_mkdir(fullpath.c_str(), PLFSUNIT_DEFAULT_DIR_MODE);
	    CPPUNIT_ASSERT_EQUAL(0, (int)ret);
	}
    }
    ret = plfs_rmdir(pathname);
    CPPUNIT_ASSERT_EQUAL(PLFS_ENOTEMPTY, ret);
    ret = plfs_readdir(pathname, &readres);
    CPPUNIT_ASSERT_EQUAL(0, (int)ret);
    for (it=readres.begin() ; it != readres.end(); it++) {
	if (*it == "." || *it == "..") continue;
	string fullpath = path + "/" + *it;
	ret = plfs_rmdir(fullpath.c_str());
	CPPUNIT_ASSERT_EQUAL(0, (int)ret);
	dents.erase("/" + *it);
    }
    CPPUNIT_ASSERT(dents.empty());
    ret = plfs_rmdir(pathname);
    CPPUNIT_ASSERT_EQUAL(0, (int)ret);
}