From 370fc55e1b5aee1f96f50ae67594acf893974394 Mon Sep 17 00:00:00 2001 From: Wolfgang Sourdeau Date: Fri, 5 Sep 2014 10:35:49 -0400 Subject: [PATCH 1/3] PLAT-653: ensure "try" methods of fs utilities do not throw during common failures --- service/fs_utils.cc | 32 +++++++++++++++++--------------- service/fs_utils.h | 8 ++++---- service/s3.cc | 2 +- 3 files changed, 22 insertions(+), 20 deletions(-) diff --git a/service/fs_utils.cc b/service/fs_utils.cc index 017884de..f1bf7cc9 100644 --- a/service/fs_utils.cc +++ b/service/fs_utils.cc @@ -62,20 +62,27 @@ static FsObjectInfo extractInfo(const struct stat & stats) struct LocalUrlFsHandler : public UrlFsHandler { - virtual FsObjectInfo getInfo(const Url & url) const + virtual FsObjectInfo getInfo(const Url & url) + const { + FsObjectInfo info; + struct stat stats; string path = url.path(); // cerr << "fs info on path: " + path + "\n"; int res = ::stat(path.c_str(), &stats); - if (res == -1) { - throw ML::Exception(errno, "stat"); + if (res == 0) { + info = extractInfo(stats); + } + else { + if (errno != ENOENT) { + throw ML::Exception(errno, "stat"); + } } // TODO: owner ID (uid) and name (uname) - - return extractInfo(stats); + return info; } virtual void makeDirectory(const Url & url) const @@ -196,9 +203,10 @@ namespace Datacratic { /* URLFSHANDLER */ -size_t +int64_t UrlFsHandler:: -getSize(const Url & url) const +getSize(const Url & url) + const { return getInfo(url).size; } @@ -238,16 +246,10 @@ getUriObjectInfo(const std::string & url) FsObjectInfo tryGetUriObjectInfo(const std::string & url) { - JML_TRACE_EXCEPTIONS(false); - try { - return getUriObjectInfo(url); - } - catch (...) { - return FsObjectInfo(); - } + return getUriObjectInfo(url); } -size_t +int64_t getUriSize(const std::string & url) { Url realUrl = makeUrl(url); diff --git a/service/fs_utils.h b/service/fs_utils.h index abbf4a55..a03fe906 100644 --- a/service/fs_utils.h +++ b/service/fs_utils.h @@ -72,7 +72,7 @@ OnUriObject; struct UrlFsHandler { virtual FsObjectInfo getInfo(const Url & url) const = 0; - virtual size_t getSize(const Url & url) const; + virtual int64_t getSize(const Url & url) const; virtual std::string getEtag(const Url & url) const; virtual void makeDirectory(const Url & url) const = 0; @@ -101,11 +101,11 @@ void registerUrlFsHandler(const std::string & scheme, FsObjectInfo getUriObjectInfo(const std::string & filename); // Return the object info for either a file or an S3 object, or null if -// it doesn't exist -FsObjectInfo tryGetUriObjectInfo(const std::string & filename); +// it doesn't exist (deprecated, use getUriObjectInfo instead) +FsObjectInfo tryGetUriObjectInfo(const std::string & filename) __attribute__((__deprecated__)); // Return an URI for either a file or an s3 object -size_t getUriSize(const std::string & filename); +int64_t getUriSize(const std::string & filename); // Return an etag for either a file or an s3 object std::string getUriEtag(const std::string & filename); diff --git a/service/s3.cc b/service/s3.cc index cf953e3d..9b204a27 100644 --- a/service/s3.cc +++ b/service/s3.cc @@ -57,7 +57,7 @@ struct S3UrlFsHandler : public UrlFsHandler { { string bucket = url.host(); auto api = getS3ApiForBucket(bucket); - return api->getObjectInfo(bucket, url.path().substr(1)); + return api->tryGetObjectInfo(bucket, url.path().substr(1)); } virtual void makeDirectory(const Url & url) const From 54844b713fc24daa7b61a4de2f26ded013ef67c1 Mon Sep 17 00:00:00 2001 From: Wolfgang Sourdeau Date: Tue, 23 Sep 2014 10:13:22 -0400 Subject: [PATCH 2/3] PLAT-653: removed tryGetInfo from UrlFsHandler interface --- service/fs_utils.h | 1 - service/s3.cc | 7 ------- 2 files changed, 8 deletions(-) diff --git a/service/fs_utils.h b/service/fs_utils.h index 8fa8a07b..a03fe906 100644 --- a/service/fs_utils.h +++ b/service/fs_utils.h @@ -71,7 +71,6 @@ OnUriObject; struct UrlFsHandler { virtual FsObjectInfo getInfo(const Url & url) const = 0; - virtual FsObjectInfo tryGetInfo(const Url & url) const = 0; virtual int64_t getSize(const Url & url) const; virtual std::string getEtag(const Url & url) const; diff --git a/service/s3.cc b/service/s3.cc index b0c6ce0b..7b52a393 100644 --- a/service/s3.cc +++ b/service/s3.cc @@ -60,13 +60,6 @@ struct S3UrlFsHandler : public UrlFsHandler { return api->tryGetObjectInfo(bucket, url.path().substr(1)); } - virtual FsObjectInfo tryGetInfo(const Url & url) const - { - string bucket = url.host(); - auto api = getS3ApiForBucket(bucket); - return api->tryGetObjectInfo(bucket, url.path().substr(1)); - } - virtual void makeDirectory(const Url & url) const { } From 147b397d3002eafc2d96cd59962a952ccb783ece Mon Sep 17 00:00:00 2001 From: Wolfgang Sourdeau Date: Tue, 23 Sep 2014 10:27:48 -0400 Subject: [PATCH 3/3] adjust declaration and documentation --- service/fs_utils.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/service/fs_utils.h b/service/fs_utils.h index a03fe906..20226001 100644 --- a/service/fs_utils.h +++ b/service/fs_utils.h @@ -97,18 +97,18 @@ void registerUrlFsHandler(const std::string & scheme, /* FREE FUNCTIONS */ /*****************************************************************************/ -// Return the object info for either a file or an S3 object -FsObjectInfo getUriObjectInfo(const std::string & filename); +// Return the object info for the given url and throws if it does not exist +FsObjectInfo getUriObjectInfo(const std::string & url); -// Return the object info for either a file or an S3 object, or null if -// it doesn't exist (deprecated, use getUriObjectInfo instead) -FsObjectInfo tryGetUriObjectInfo(const std::string & filename) __attribute__((__deprecated__)); +// Return the object info for either a file or an S3 object or an empty +// FsObjectInfo it doesn't exist +FsObjectInfo tryGetUriObjectInfo(const std::string & url); -// Return an URI for either a file or an s3 object -int64_t getUriSize(const std::string & filename); +// Return the file size for the given url +int64_t getUriSize(const std::string & url); // Return an etag for either a file or an s3 object -std::string getUriEtag(const std::string & filename); +std::string getUriEtag(const std::string & url); /* Create the directories for the given path. For S3 it does nothing; for normal directories it does mkdir -p