Commit f2f9118d authored by Ramon Nou's avatar Ramon Nou
Browse files

solve rename

parent 05b4b8dc
Loading
Loading
Loading
Loading
+29 −31
Original line number Diff line number Diff line
@@ -431,19 +431,12 @@ gkfs_access(const std::string& path, const int mask, bool follow_links) {
int
gkfs_rename(const string& old_path, const string& new_path) {
    auto md_old = gkfs::utils::get_metadata(old_path, false);

    std::string original_path = old_path;
    // if the file is not found, or it is a renamed one cancel.
    if(!md_old || md_old.value().blocks() == -1) {
        return -1;
    }
    if(!md_old.value().target_path().empty()) {
        // the file is a renamed one, we need to get the metadata of the
        // original file. (There will be only one level)
        md_old = gkfs::utils::get_metadata(md_old.value().target_path(), false);
        if(!md_old) {
            return -1;
        }
    }


    auto md_new = gkfs::utils::get_metadata(new_path, false);
    if(md_new) {
@@ -454,22 +447,11 @@ gkfs_rename(const string& old_path, const string& new_path) {
            // the original file.
            LOG(DEBUG, "Destroying Circular Rename '{}' --> '{}'", old_path,
                new_path);
            gkfs::metadata::MetadentryUpdateFlags flags{};
            flags.atime = false;
            flags.mtime = false;
            flags.ctime = false;
            flags.blocks = true;
            flags.mode = false;
            flags.size = false;
            flags.uid = false;
            flags.gid = false;
            flags.link_count = false;

            md_old.value().blocks(0);
            md_old.value().target_path("");

            auto err = gkfs::rpc::forward_update_metadentry(
                    new_path, md_old.value(), flags, 0);

            // We update the target_path
            auto err = gkfs::rpc::forward_rename(new_path, "", md_old.value());
            if(err) {
                errno = err;
                return -1;
@@ -487,14 +469,31 @@ gkfs_rename(const string& old_path, const string& new_path) {
            return 0;
        }
        return -1;
    }
    } else {

    auto err = gkfs::rpc::forward_rename(old_path, new_path, md_old.value());
        if(!md_old.value().target_path().empty()) {
            // the file is a renamed one, we need to get the metadata of the
            // original file. (There will be only one level)
            original_path = md_old.value().target_path();

            md_old = gkfs::utils::get_metadata(original_path, false);

            if(!md_old) {
                return -1;
            }
            auto is_dir = false;
            if(S_ISDIR(md_old->mode()))
                is_dir = true;
            // Remove intermediate file
            gkfs::rpc::forward_remove(old_path, is_dir, CTX->get_replicas());
        }
        auto err = gkfs::rpc::forward_rename(original_path, new_path,
                                             md_old.value());
        if(err) {
            errno = err;
            return -1;
        }

    }
    return 0;
}
#endif
@@ -839,7 +838,7 @@ gkfs_truncate(const std::string& path, off_t length) {
    }

    // If rename is enabled we need to check if the file is renamed
#ifdef HAS_SYMLINKS

#ifdef HAS_RENAME
    if(md.value().blocks() == -1) {
        errno = ENOENT;
@@ -860,7 +859,6 @@ gkfs_truncate(const std::string& path, off_t length) {
        }
        return gkfs_truncate(new_path, size, length);
    }
#endif
#endif

    auto size = md->size();
+25 −0
Original line number Diff line number Diff line
@@ -406,9 +406,34 @@ int
forward_rename(const string& oldpath, const string& newpath,
               const gkfs::metadata::Metadata& md) {


    auto endp = CTX->hosts().at(
            CTX->distributor()->locate_file_metadata(oldpath, 0));

    if(newpath == "") { // Just cleanup rename status
        try {
            LOG(DEBUG, "Sending RPC ...");
            // TODO(amiranda): add a post() with RPC_TIMEOUT to hermes so that
            // we can retry for RPC_TRIES (see old commits with margo)
            // TODO(amiranda): hermes will eventually provide a post(endpoint)
            // returning one result and a broadcast(endpoint_set) returning a
            // result_set. When that happens we can remove the .at(0) :/
            auto out = ld_network_service
                               ->post<gkfs::rpc::rename>(endp, oldpath, newpath)
                               .get()
                               .at(0);

            LOG(DEBUG, "Got response success: {}", out.err());

            // return out.err() ? out.err() : 0;
            return 0;
        } catch(const std::exception& ex) {
            LOG(ERROR, "while getting rpc output");
            return EBUSY;
        }
    }


    try {
        LOG(DEBUG, "Sending RPC ...");
        // TODO(amiranda): add a post() with RPC_TIMEOUT to hermes so that we
+5 −3
Original line number Diff line number Diff line
@@ -935,10 +935,12 @@ rpc_srv_rename(hg_handle_t handle) {
    try {
        gkfs::metadata::Metadata md = gkfs::metadata::get(in.path);

        // if(md.blocks() == -1) {
        // We need to fill the rename path as this is an inverse path
        // old -> new

        md.target_path(in.target_path);
        // We are reverting the rename so we clean up the target_path
        if(strcmp(in.target_path, "") == 0)
            md.blocks(0);

        //}
        GKFS_DATA->spdlogger()->debug(
                "{}() Updating path '{}' with metadata '{}'", __func__, in.path,