Skip to content
Open
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
14 changes: 14 additions & 0 deletions src/lib/object_store/File.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,20 @@ File::~File()
}
}

// Check if a file exists without trying to open it
// May be used when a routine just wants to check file existence,
// and does not want to throw an error by trying to open it.
bool File::exists(const std::string& path)
{
#ifndef _WIN32
struct stat buf;
return stat(path.c_str(), &buf) == 0;
#else
return _access(path.c_str(), 0) == 0;
#endif
}


// Check if the file is valid
bool File::isValid()
{
Expand Down
5 changes: 5 additions & 0 deletions src/lib/object_store/File.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ class File
// Destructor
virtual ~File();

// Check if a file exists without trying to open it
// May be used when a routine just wants to check file existence,
// and does not want to throw an error by trying to open it.
static bool exists(const std::string& path);

// Check if the file is valid
bool isValid();

Expand Down
7 changes: 7 additions & 0 deletions src/lib/object_store/Generation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ bool Generation::sync(File &objectFile)
// Check if the target was updated
bool Generation::wasUpdated()
{

// Check if path file exists before anything
if (!File::exists(path))
{
return true;
}

if (isToken)
{
MutexLocker lock(genMutex);
Expand Down
Loading