Nymph  v1.5.2
Flow-Based Data Processing Framework
KTDirectory.cc
Go to the documentation of this file.
1 /*
2  * KTDirectory.cc
3  *
4  * Created on: Dec 3, 2012
5  * Author: nsoblath
6  */
7 
8 #include "KTDirectory.hh"
9 
10 #include "KTLogger.hh"
11 
12 #include <unistd.h>
13 
14 using std::string;
15 
16 using boost::filesystem::path;
17 
18 namespace Nymph
19 {
20  KTLOGGER(dirlog, "KTDirectory");
21 
23  fPath(""),
24  fPathExists(false),
25  fAccess(eNone)
26  {
27  SetPath("./");
28  }
29 
31  {
32  }
33 
34  const string& KTDirectory::GetPath() const
35  {
36  return fPath.string();
37  }
38 
40  {
41  return fPathExists;
42  }
43 
45  {
46  return fAccess;
47  }
48 
49  bool KTDirectory::SetPath(const string& strPath)
50  {
51  path newPath(strPath);
52  if (! newPath.is_absolute())
53  {
54  newPath = absolute(newPath);
55  }
56  if (! exists(newPath))
57  {
58  KTERROR(dirlog, "Path does not exist: " << strPath);
59  return false;
60  }
61  if (! is_directory(newPath))
62  {
63  KTERROR(dirlog, "Path specified is not a directory: " << strPath);
64  return false;
65  }
66  fPathExists = true;
67  fPath = newPath;
68 
69  // set access
70  if (access(strPath.c_str(), R_OK | W_OK) != -1)
71  {
73  }
74  else if (access(strPath.c_str(), R_OK))
75  {
76  fAccess = eRead;
77  }
78  else
79  {
80  fAccess = eNone;
81  }
82 
83  return true;
84  }
85 
86 } /* namespace Nymph */
Access GetAccess() const
Definition: KTDirectory.cc:44
::Nymph::KTLogger dirlog("KTCacheDirectory")
bool SetPath(const std::string &strPath)
Definition: KTDirectory.cc:49
KTLOGGER(applog, "KTApplication")
bool GetPathExists() const
Definition: KTDirectory.cc:39
#define KTERROR(...)
Definition: KTLogger.hh:347
boost::filesystem::path fPath
Definition: KTDirectory.hh:40
const std::string & GetPath() const
Definition: KTDirectory.cc:34
virtual ~KTDirectory()
Definition: KTDirectory.cc:30
Contains the logger class and macros, based on Kasper&#39;s KLogger class.