#include "blob.h" #include "repo.h" #include #include #include #include #include #include #include #include #include GitFS::Blob::Blob(const Repo * const r, std::string && path) : repo(r), entry(Git::TreeEntryByPath(repo->tree, path)), blob(getBlob()), blobSize(git_blob_rawsize(blob.get())), blobContent(static_cast(git_blob_rawcontent(blob.get()))) { } GitFS::Git::BlobPtr GitFS::Blob::getBlob() const { const auto mode = git_tree_entry_filemode(entry.get()); if (S_ISDIR(mode)) { throw NetFS::SystemError(EISDIR); } if (S_ISLNK(mode)) { throw NetFS::SystemError(ELOOP); } return Git::BlobLookup(repo->repo, *git_tree_entry_id(entry.get())); } void GitFS::Blob::close(const ::Ice::Current & current) { current.adapter->remove(current.id); } NetFS::Attr GitFS::Blob::fgetattr(ReqEnv, const ::Ice::Current &) { NetFS::Attr a; a << *blob << *entry << *repo->commit; a.gid = repo->gid; a.uid = repo->uid; return a; } NetFS::Buffer GitFS::Blob::read(long long int o, long long int s, const ::Ice::Current &) { const auto offset {static_cast(o)}; const auto size {static_cast(s)}; if (offset > blobSize) { return {}; } auto len = std::min(blobSize - offset, size); return {blobContent + offset, blobContent + offset + len}; } void GitFS::Blob::ftruncate(ReqEnv, long long int, const ::Ice::Current &) { throw NetFS::SystemError(EROFS); } void GitFS::Blob::write(long long int, long long int, Buffer, const ::Ice::Current &) { throw NetFS::SystemError(EROFS); } long long int GitFS::Blob::copyrange(FilePrxPtr, long long int, long long int, long long int, int, const Ice::Current &) { throw NetFS::SystemError(EROFS); }