Verified Commit b8281adb authored by Tommaso Tocci's avatar Tommaso Tocci
Browse files

Implement rmdir

parent ed21998f
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -57,4 +57,6 @@ int adafs_opendir(const std::string& path);

struct dirent * adafs_readdir(int fd);

int adafs_rmdir(const std::string& path);

#endif //IFS_ADAFS_FUNCTIONS_HPP
+1 −0
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ class OpenDir: public OpenFile {
        OpenDir(const std::string& path);
        void add(const std::string& name, const FileType& type);
        struct dirent * readdir();
        size_t size();
};


+17 −0
Original line number Diff line number Diff line
@@ -230,6 +230,23 @@ int adafs_opendir(const std::string& path) {
    return CTX->file_map()->add(open_dir);
}

int adafs_rmdir(const std::string& path) {
    init_ld_env_if_needed();
#if defined(DO_LOOKUP)
    auto err = rpc_send_access(path, F_OK);
    if(err != 0){
        return err;
    }
#endif
    auto open_dir = std::make_shared<OpenDir>(path);
    rpc_send_get_dirents(*open_dir);
    if(open_dir->size() != 0){
        errno = ENOTEMPTY;
        return -1;
    }
    return rpc_send_rm_node(path, true);
}

struct dirent * adafs_readdir(int fd){
    init_ld_env_if_needed();
    CTX->log()->trace("{}() called on fd: {}", __func__, fd);
+1 −2
Original line number Diff line number Diff line
@@ -119,8 +119,7 @@ int rmdir(const char* path) __THROW {
    CTX->log()->trace("{}() called with path {}", __func__, path);
    std::string rel_path(path);
    if (CTX->relativize_path(rel_path)) {
        // XXX Possible need another call to specifically handle remove dirs. For now handle them the same as files
        return adafs_rm_node(rel_path);
        return adafs_rmdir(rel_path);
    }
    return (reinterpret_cast<decltype(&rmdir)>(libc_rmdir))(path);
}
+4 −0
Original line number Diff line number Diff line
@@ -50,3 +50,7 @@ struct dirent * OpenDir::readdir(){
    is_dirent_valid = true;
    return &dirent_;
}

size_t OpenDir::size(){
    return entries.size();
}
Loading