PetaVision  Alpha
CheckpointEntry.cpp
1 /*
2  * CheckpointEntry.cpp
3  *
4  * Created on Sep 27, 2016
5  * Author: Pete Schultz
6  */
7 
8 #include "CheckpointEntry.hpp"
9 #include "io/fileio.hpp"
10 #include "utils/PVLog.hpp"
11 #include <cerrno>
12 #include <cstring>
13 #include <sys/stat.h>
14 #include <unistd.h>
15 
16 namespace PV {
17 
18 std::string CheckpointEntry::generatePath(
19  std::string const &checkpointDirectory,
20  std::string const &extension) const {
21  std::string path{checkpointDirectory};
22  path.append("/").append(getName()).append(".").append(extension);
23  return path;
24 }
25 
26 void CheckpointEntry::deleteFile(
27  std::string const &checkpointDirectory,
28  std::string const &extension) const {
29  if (getMPIBlock()->getRank() == 0) {
30  std::string path = generatePath(checkpointDirectory, extension);
31  struct stat pathStat;
32  int statstatus = stat(path.c_str(), &pathStat);
33  if (statstatus == 0) {
34  int unlinkstatus = unlink(path.c_str());
35  if (unlinkstatus != 0) {
36  Fatal().printf("Failure deleting \"%s\": %s\n", path.c_str(), strerror(errno));
37  }
38  }
39  }
40 }
41 } // end namespace PV