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

bugfix: rmdir must not remove regular file

parent c0791174
Loading
Loading
Loading
Loading
+12 −5
Original line number Diff line number Diff line
@@ -459,12 +459,19 @@ int adafs_opendir(const std::string& path) {

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;

    auto md = adafs_metadata(path);
    if (!md) {
        CTX->log()->debug("{}() path does not exists: '{}'", __func__, path);
        errno = ENOENT;
        return -1;
    }
#endif
    if (!S_ISDIR(md->mode())) {
        CTX->log()->debug("{}() path is not a directory", __func__);
        errno = ENOTDIR;
        return -1;
    }

    auto open_dir = std::make_shared<OpenDir>(path);
    rpc_send_get_dirents(*open_dir);
    if(open_dir->size() != 0){
+22 −0
Original line number Diff line number Diff line
@@ -54,6 +54,17 @@ int main(int argc, char* argv[]) {
        return -1;
    }

    // Remove nonexisting directory
    ret = rmdir(nonexisting.c_str());
    if (ret == 0) {
        std::cerr << "Succeded on removing nonexisitng directory" << std::endl;
        return EXIT_FAILURE;
    }
    if (errno != ENOENT) {     
        std::cerr << "Wrong error number on removing nonexisitng directory: " << std::strerror(errno) << std::endl;
        return EXIT_FAILURE;
    }

    // Close nonexisting directory
    ret = closedir(NULL);
    if(ret != -1 || errno != EINVAL){
@@ -172,6 +183,17 @@ int main(int argc, char* argv[]) {
    }
    assert(found_dirents  == expected_dirents);

    // Remove file through rmdir should reise error
    ret = rmdir(file_a.c_str());
    if (ret == 0) {
        std::cerr << "ERROR: Succeded on removing file through rmdir function" << std::endl;
        return EXIT_FAILURE;
    }
    if (errno != ENOTDIR) {     
        std::cerr << "ERROR: Wrong error number on removing file through rmdir function: " << std::strerror(errno) << std::endl;
        return EXIT_FAILURE;
    }

    if(closedir(dirstream) != 0){
        std::cerr << "Error closing topdir" << std::strerror(errno) << std::endl;
        return -1;