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

create path tmp

parent 12ac0bc9
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -28,6 +28,12 @@ class Metadata;
}

namespace rpc {
// enum definieren TODO
enum class ForwardCreateStatus {
    ok,
    exists,
    error = -1
};

int forward_create(const std::string& path, mode_t mode);

+5 −0
Original line number Diff line number Diff line
@@ -30,6 +30,11 @@ public:
    explicit NotFoundException(const std::string& s) : DBException(s) {};
};

class CreateException : public DBException {
public:
    CreateException(const std::string& s) : DBException(s) {};
};

} // namespace metadata
} // namespace gkfs

+48 −46
Original line number Diff line number Diff line
@@ -100,46 +100,49 @@ int gkfs_open(const std::string& path, mode_t mode, int flags) {
        return -1;
    }

    bool exists = true;
    auto md = gkfs::util::get_metadata(path);
    if (!md) {
        if (errno == ENOENT) {
            exists = false;
        } else {
            LOG(ERROR, "Error while retriving stat to file");
            return -1;
        }
    }

    if (!exists) {
        if (!(flags & O_CREAT)) {
            // file doesn't exists and O_CREAT was not set
            errno = ENOENT;
            return -1;
        }

        /***   CREATION    ***/
        assert(flags & O_CREAT);
    // dummy metadata creation
    std::shared_ptr<gkfs::metadata::Metadata> md{};

    if (flags & O_CREAT) {
        if (flags & O_DIRECTORY) {
            LOG(ERROR, "O_DIRECTORY use with O_CREAT. NOT SUPPORTED");
            errno = ENOTSUP;
            return -1;
        }

        // no access check required here. If one is using our FS they have the permissions.
        if (gkfs_create(path, mode | S_IFREG)) {
            LOG(ERROR, "Error creating non-existent file: '{}'", strerror(errno));
        int err_code = gkfs_create(path, mode | S_IFREG);
        if (err_code == (int) gkfs::rpc::ForwardCreateStatus::error) {
            LOG(ERROR, "Error creating file: '{}'", strerror(errno));
            return -1;
        }
    } else {
        /* File already exists */

        if (err_code == (int) gkfs::rpc::ForwardCreateStatus::exists) {
            // file exists, O_CREAT was set
            if (flags & O_EXCL) {
            // File exists and O_EXCL was set
                // File exists and O_EXCL & O_CREAT was set
                errno = EEXIST;
                return -1;
            }
            // file exists, O_CREAT was set O_EXCL wasnt, so function does not fail
            md = gkfs::util::get_metadata(path);
        }
        if (err_code == 0) {
            // file was created
            return CTX->file_map()->add(std::make_shared<gkfs::filemap::OpenFile>(path, flags));
        }

    } else {
        md = gkfs::util::get_metadata(path);
        if (!md) {
            if (errno == ENOENT) {
                // file doesn't exists and O_CREAT was not set
                return -1;
            } else {
                LOG(ERROR, "Error statting existing file");
                return -1;
            }
        }
    }
    // **file exists**

#ifdef HAS_SYMLINKS
    if (md->is_link()) {
@@ -166,7 +169,6 @@ int gkfs_open(const std::string& path, mode_t mode, int flags) {
            return -1;
        }
    }
    }

    return CTX->file_map()->add(std::make_shared<gkfs::filemap::OpenFile>(path, flags));
}
+7 −3
Original line number Diff line number Diff line
@@ -41,17 +41,21 @@ int forward_create(const std::string& path, const mode_t mode) {
        // result_set. When that happens we can remove the .at(0) :/
        auto out = ld_network_service->post<gkfs::rpc::create>(endp, path, mode).get().at(0);
        err = out.err();
        LOG(DEBUG, "Got response success: {}", err);

        LOG(ERROR, "Got response success: {}", err)
        if (out.err() == (int) gkfs::rpc::ForwardCreateStatus::exists) {
            errno = out.err();
            return (int) gkfs::rpc::ForwardCreateStatus::exists;
        }
        if (out.err()) {
            errno = out.err();
            return -1;
            return (int) gkfs::rpc::ForwardCreateStatus::error;
        }

    } catch (const std::exception& ex) {
        LOG(ERROR, "while getting rpc output");
        errno = EBUSY;
        return -1;
        return (int) gkfs::rpc::ForwardCreateStatus::error;
    }

    return err;
+1 −0
Original line number Diff line number Diff line
@@ -155,6 +155,7 @@ void init_environment() {
    GKFS_DATA->spdlogger()->debug("{}() Initializing metadata DB: '{}'", __func__, metadata_path);
    try {
        GKFS_DATA->mdb(std::make_shared<gkfs::metadata::MetadataDB>(metadata_path));
    } catch (const CreateException& e) {
    } catch (const std::exception& e) {
        GKFS_DATA->spdlogger()->error("{}() Failed to initialize metadata DB: {}", __func__, e.what());
        throw;
Loading