// TODO: DO NOT use a hardcoded path
Status GetTmpFilename(string* filename) {
- if (!filename) {
- return errors::Internal("'filename' cannot be nullptr.");
- }
#ifndef _WIN32
char buffer[] = "/tmp/gcs_filesystem_XXXXXX";
int fd = mkstemp(buffer);
/// object is empty.
Status ParseGcsPath(StringPiece fname, bool empty_object_ok, string* bucket,
string* object) {
- if (!bucket || !object) {
- return errors::Internal("bucket and object cannot be null.");
- }
StringPiece scheme, bucketp, objectp;
io::ParseURI(fname, &scheme, &bucketp, &objectp);
if (scheme != "gs") {
}
Status GetCurrentFileSize(uint64* size) {
- if (size == nullptr) {
- return errors::Internal("'size' cannot be nullptr");
- }
const auto tellp = outfile_.tellp();
if (tellp == static_cast<std::streampos>(-1)) {
return errors::Internal(
/// Initiates a new resumable upload session.
Status CreateNewUploadSession(string* session_uri) {
- if (session_uri == nullptr) {
- return errors::Internal("'session_uri' cannot be nullptr.");
- }
uint64 file_size;
TF_RETURN_IF_ERROR(GetCurrentFileSize(&file_size));
/// uploaded size in bytes.
Status RequestUploadSessionStatus(const string& session_uri, bool* completed,
uint64* uploaded) {
- if (completed == nullptr || uploaded == nullptr) {
- return errors::Internal("'completed' and 'uploaded' cannot be nullptr.");
- }
uint64 file_size;
TF_RETURN_IF_ERROR(GetCurrentFileSize(&file_size));
Status GcsFileSystem::ObjectExists(const string& fname, const string& bucket,
const string& object, bool* result) {
- if (!result) {
- return errors::Internal("'result' cannot be nullptr.");
- }
GcsFileStat stat;
const Status status = StatForObject(fname, bucket, object, &stat);
switch (status.code()) {
Status GcsFileSystem::StatForObject(const string& fname, const string& bucket,
const string& object, GcsFileStat* stat) {
- if (!stat) {
- return errors::Internal("'stat' cannot be nullptr.");
- }
if (object.empty()) {
return errors::InvalidArgument(strings::Printf(
"'object' must be a non-empty string. (File: %s)", fname.c_str()));
}
Status GcsFileSystem::BucketExists(const string& bucket, bool* result) {
- if (!result) {
- return errors::Internal("'result' cannot be nullptr.");
- }
-
std::unique_ptr<HttpRequest> request;
TF_RETURN_IF_ERROR(CreateHttpRequest(&request));
request->SetUri(strings::StrCat(kGcsUriBase, "b/", bucket));
}
Status GcsFileSystem::FolderExists(const string& dirname, bool* result) {
- if (!result) {
- return errors::Internal("'result' cannot be nullptr.");
- }
StatCache::ComputeFunc compute_func = [this](const string& dirname,
GcsFileStat* stat) {
std::vector<string> children;