diff options
Diffstat (limited to 'src/blob.cpp')
-rw-r--r-- | src/blob.cpp | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/src/blob.cpp b/src/blob.cpp index 2211736..285cd0b 100644 --- a/src/blob.cpp +++ b/src/blob.cpp @@ -2,17 +2,16 @@ #include "repo.h" #include <Ice/Current.h> #include <Ice/ObjectAdapter.h> -#include <algorithm> #include <cerrno> #include <exceptions.h> #include <file.h> -#include <memory> +#include <numeric.h> #include <sys/stat.h> #include <types.h> -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<const char *>(git_blob_rawcontent(blob.get()))) +GitFS::Blob::Blob(const Repo * const repo, const std::string & path) : + repo(repo), entry(Git::treeEntryByPath(repo->tree, path)), blob(getBlob()), + blobContent(static_cast<const ::Ice::Byte *>(git_blob_rawcontent(blob.get())), git_blob_rawsize(blob.get())) { } @@ -28,35 +27,36 @@ GitFS::Blob::getBlob() const throw NetFS::SystemError(ELOOP); } - return Git::BlobLookup(repo->repo, *git_tree_entry_id(entry.get())); + return Git::blobLookup(repo->repo, *git_tree_entry_id(entry.get())); } void -GitFS::Blob::close(const ::Ice::Current & current) +GitFS::Blob::close(const ::Ice::Current & ice) { - current.adapter->remove(current.id); + ice.adapter->remove(ice.id); } NetFS::Attr GitFS::Blob::fgetattr(const ::Ice::Current &) { - NetFS::Attr a; - a << *blob << *entry << *repo->commit; - a.gid = repo->gid; - a.uid = repo->uid; - return a; + 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 o, long long int s, const ::Ice::Current &) +GitFS::Blob::read(long long int offsetSized, long long int sizeLong, const ::Ice::Current &) { - const auto offset {static_cast<BlobSize>(o)}; - const auto size {static_cast<BlobSize>(s)}; - if (offset > blobSize) { + const size_t offset = safe {offsetSized}; + if (offset > blobContent.size()) { return {}; } - auto len = std::min(blobSize - offset, size); - return {blobContent + offset, blobContent + offset + len}; + 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 |