Commit e8f45190 authored by Marc Vef's avatar Marc Vef
Browse files

adafs_unlink() implemented (called by rm)

parent 37703804
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -5,7 +5,7 @@
#include "access.h"

/**
 * Checks access for mask (can be R_OK, W_OK, or R_OK | W_OK AFAIK and not verified) against metadata's mode.
 * Checks access for mask (can be R_OK, W_OK, or X_OK (or combined) AFAIK and not verified) against metadata's mode.
 * First the mask is checked agains the 3 bits for the user, then for the 3 bits of the group, and lastly other.
 * If all three checks have failed, return -EACCESS (no access)
 * @param md
+18 −1
Original line number Diff line number Diff line
@@ -69,7 +69,7 @@ int create_dentry(const unsigned long parent_dir_hash, const string& fname) {
    // XXX Errorhandling
    auto f_path = bfs::path(ADAFS_DATA->dentry_path);
    f_path /= to_string(parent_dir_hash);
    if (!bfs::exists(f_path)) return 1;
    if (!bfs::exists(f_path)) return -ENOENT;

    f_path /= fname;

@@ -79,3 +79,20 @@ int create_dentry(const unsigned long parent_dir_hash, const string& fname) {

    return 0;
}

int remove_dentry(const unsigned long parent_dir_hash, const string& fname) {
    auto f_path = bfs::path(ADAFS_DATA->dentry_path);
    f_path /= to_string(parent_dir_hash);
    if (!bfs::exists(f_path)) {
        ADAFS_DATA->logger->error("remove_dentry() dentry_path '{}' not found", f_path.string());
        return -ENOENT;
    }

    f_path /= fname;
    // remove dentry here
    bfs::remove(f_path);

    // XXX make sure dentry has been deleted

    return 0;
}
 No newline at end of file
+2 −0
Original line number Diff line number Diff line
@@ -15,4 +15,6 @@ int read_dentries(std::vector<std::string>& dir, const unsigned long hash);

int create_dentry(const unsigned long parent_dir_hash, const std::string& fname);

int remove_dentry(const unsigned long parent_dir_hash, const std::string& fname);

#endif //FS_DENTRY_OPS_H
+22 −1
Original line number Diff line number Diff line
@@ -59,7 +59,7 @@ bool read_all_metadata(Metadata& md, const unsigned long hash) {


template<typename T>
unique_ptr<T> read_metadata_field(const uint64_t hash, const string& leaf_name) {
unique_ptr<T> read_metadata_field(const unsigned long hash, const string& leaf_name) {
    auto path = bfs::path(ADAFS_DATA->inode_path);
    path /= to_string(hash);
    path /= leaf_name;
@@ -90,6 +90,27 @@ int get_metadata(Metadata& md, const bfs::path& path) {
    }
}

/**
 * Returns the metadata of an object based on its hash
 * @param path
 * @return
 */
// XXX Errorhandling
int remove_metadata(const unsigned long hash) {
    auto i_path = bfs::path(ADAFS_DATA->inode_path);
    i_path /= to_string(hash);
    // XXX below could be omitted
    if (!bfs::exists(i_path)) {
        ADAFS_DATA->logger->error("remove_metadata() metadata_path '{}' not found", i_path.string());
        return -ENOENT;
    }

    bfs::remove_all(i_path);
    // XXX make sure metadata has been deleted

    return 0;
}




+3 −1
Original line number Diff line number Diff line
@@ -18,10 +18,12 @@ bool write_metadata_field(const T& field, const unsigned long hash, const string
bool read_all_metadata(Metadata& md, const unsigned long hash);

template<typename T>
unique_ptr<T> read_metadata_field(const uint64_t hash, const string& leaf_name);
unique_ptr<T> read_metadata_field(const unsigned long hash, const string& leaf_name);

int get_metadata(Metadata& md, const std::string& path);

int get_metadata(Metadata& md, const boost::filesystem::path& path);

int remove_metadata(const unsigned long hash);

#endif //FS_METADATA_OPS_H
Loading