示例#1
0
static void
test_MkDir_and_Is_Directory(TestBatch *batch)
{
    Folder *folder = (Folder*)RAMFolder_new(NULL);
    FileHandle *fh;

    TEST_FALSE(batch, Folder_Is_Directory(folder, &foo), 
        "Is_Directory() false for non-existent entry");

    TEST_TRUE(batch, Folder_MkDir(folder, &foo), 
        "MkDir returns true on success");
    TEST_TRUE(batch, Folder_Is_Directory(folder, &foo), 
        "Is_Directory() true for local folder");

    TEST_FALSE(batch, Folder_Is_Directory(folder, &foo_bar_baz), 
        "Is_Directory() false for non-existent deeply nested dir");
    Err_set_error(NULL);
    TEST_FALSE(batch, Folder_MkDir(folder, &foo_bar_baz), 
        "MkDir for deeply nested dir fails");
    TEST_TRUE(batch, Err_get_error() != NULL,
        "MkDir for deeply nested dir sets Err_error");

    TEST_TRUE(batch, Folder_MkDir(folder, &foo_bar), 
        "MkDir for nested dir");
    TEST_TRUE(batch, Folder_Is_Directory(folder, &foo_bar), 
        "Is_Directory() true for nested dir");

    Err_set_error(NULL);
    TEST_FALSE(batch, Folder_MkDir(folder, &foo_bar), 
        "Overwrite dir with MkDir fails");
    TEST_TRUE(batch, Err_get_error() != NULL,
        "Overwrite dir with MkDir sets Err_error");

    fh = Folder_Open_FileHandle(folder, &foo_boffo, 
        FH_CREATE | FH_WRITE_ONLY);
    DECREF(fh);
    Err_set_error(NULL);
    TEST_FALSE(batch, Folder_MkDir(folder, &foo_boffo), 
        "Overwrite file with MkDir fails");
    TEST_TRUE(batch, Err_get_error() != NULL,
        "Overwrite file with MkDir sets Err_error");
    TEST_FALSE(batch, Folder_Is_Directory(folder, &foo_boffo), 
        "Is_Directory() false for nested file");

    DECREF(folder);
}
示例#2
0
文件: FilePurger.c 项目: kidaa/lucy
static Vector*
S_find_all_referenced(Folder *folder, Vector *entries) {
    Hash *uniqued = Hash_new(Vec_Get_Size(entries));
    for (uint32_t i = 0, max = Vec_Get_Size(entries); i < max; i++) {
        String *entry = (String*)Vec_Fetch(entries, i);
        Hash_Store(uniqued, entry, (Obj*)CFISH_TRUE);
        if (Folder_Is_Directory(folder, entry)) {
            Vector *contents = Folder_List_R(folder, entry);
            for (uint32_t j = Vec_Get_Size(contents); j--;) {
                String *sub_entry = (String*)Vec_Fetch(contents, j);
                Hash_Store(uniqued, sub_entry, (Obj*)CFISH_TRUE);
            }
            DECREF(contents);
        }
    }
    Vector *referenced = Hash_Keys(uniqued);
    DECREF(uniqued);
    return referenced;
}
示例#3
0
static VArray*
S_find_all_referenced(Folder *folder, VArray *entries)
{
    Hash *uniqued = Hash_new(VA_Get_Size(entries));
    for (uint32_t i = 0, max = VA_Get_Size(entries); i < max; i++) {
        CharBuf *entry = (CharBuf*)VA_Fetch(entries, i);
        Hash_Store(uniqued, (Obj*)entry, INCREF(&EMPTY));
        if (Folder_Is_Directory(folder, entry)) {
            VArray *contents = Folder_List_R(folder, entry);
            for (uint32_t j = VA_Get_Size(contents); j--; ) {
                CharBuf *sub_entry = (CharBuf*)VA_Fetch(contents, j);
                Hash_Store(uniqued, (Obj*)sub_entry, INCREF(&EMPTY));
            }
            DECREF(contents);
        }
    }
    VArray *referenced = Hash_Keys(uniqued);
    DECREF(uniqued);
    return referenced;
}