#include "blob.h" #include "repo.h" #include #include #include #include #include #include #include #include GitFS::Blob::Blob(const Repo * const repo, const std::string & path) : repo(repo), entry(Git::treeEntryByPath(repo->tree, path)), blob(getBlob()), blobContent(static_cast(git_blob_rawcontent(blob.get())), git_blob_rawsize(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 & ice) { ice.adapter->remove(ice.id); } NetFS::Attr GitFS::Blob::fgetattr(const ::Ice::Current &) { NetFS::Attr attr; attr << *blob << *entry << *repo->commit; attr.gid = repo->gid; attr.uid = repo->uid; return attr; } NetFS::Buffer GitFS::Blob::read(long long int offsetSized, long long int sizeLong, const ::Ice::Current &) { const size_t offset = safe {offsetSized}; if (offset > blobContent.size()) { return {}; } const size_t size = safe {sizeLong}; const auto len = std::min(blobContent.size() - offset, size); const auto range = blobContent.subspan(offset, len); return {range.begin(), range.end()}; } void GitFS::Blob::ftruncate(long long int, const ::Ice::Current &) { throw NetFS::SystemError(EROFS); } void GitFS::Blob::write( long long int, long long int, std::pair, 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); }