Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 24 additions & 12 deletions service/fs_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,20 @@ struct LocalUrlFsHandler : public UrlFsHandler {
return extractInfo(stats);
}

virtual FsObjectInfo tryGetInfo(const Url & url) const
{
struct stat stats;
string path = url.path();

// cerr << "fs info on path: " + path + "\n";
int res = ::stat(path.c_str(), &stats);
if (res == -1) {
return FsObjectInfo();
}

return extractInfo(stats);
}

virtual void makeDirectory(const Url & url) const
{
boost::system::error_code ec;
Expand Down Expand Up @@ -174,6 +188,9 @@ struct AtInit {
/* ensures that local filenames are represented as urls */
Url makeUrl(const string & urlStr)
{
if (urlStr.empty())
throw ML::Exception("can't makeUrl on empty url");

/* scheme is specified */
if (urlStr.find("://") != string::npos) {
return Url(urlStr);
Expand Down Expand Up @@ -232,24 +249,19 @@ void registerUrlFsHandler(const std::string & scheme,
}

FsObjectInfo
getUriObjectInfo(const std::string & url)
tryGetUriObjectInfo(const std::string & url)
{
Url realUrl = makeUrl(url);
return findFsHandler(realUrl.scheme())->getInfo(realUrl);
return findFsHandler(realUrl.scheme())->tryGetInfo(realUrl);
}

FsObjectInfo
tryGetUriObjectInfo(const std::string & url)
getUriObjectInfo(const std::string & url)
{
JML_TRACE_EXCEPTIONS(false);
try {
return getUriObjectInfo(url);
}
catch (...) {
return FsObjectInfo();
}
Url realUrl = makeUrl(url);
return findFsHandler(realUrl.scheme())->getInfo(realUrl);
}

size_t
getUriSize(const std::string & url)
{
Expand All @@ -270,7 +282,7 @@ makeUriDirectory(const std::string & url)
string dirUrl(url);
size_t slashIdx = dirUrl.rfind('/');
if (slashIdx == string::npos) {
throw ML::Exception("makeUriDirectory cannot work on filenames");
throw ML::Exception("makeUriDirectory cannot work on filenames: instead of " + url + " you should probably write file://" + url);
}
dirUrl.resize(slashIdx);

Expand Down
1 change: 1 addition & 0 deletions service/fs_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ OnUriObject;

struct UrlFsHandler {
virtual FsObjectInfo getInfo(const Url & url) const = 0;
virtual FsObjectInfo tryGetInfo(const Url & url) const = 0;

virtual size_t getSize(const Url & url) const;
virtual std::string getEtag(const Url & url) const;
Expand Down
7 changes: 7 additions & 0 deletions service/s3.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ struct S3UrlFsHandler : public UrlFsHandler {
return api->getObjectInfo(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
{
}
Expand Down
4 changes: 3 additions & 1 deletion types/url.cc
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,9 @@ std::string
Url::
path() const
{
return url->path();
if (url->scheme() == "file")
return url->host() + url->path();
else return url->path();
}

std::string
Expand Down