Changeset 151
- Timestamp:
- Aug 13, 2006, 10:30:02 PM (17 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bin/Parameter.cc
r149 r151 84 84 void Parameter::analyse(void) 85 85 { 86 // making root absolute 87 std::string workdir(pwd()); 88 chdir(root_.c_str()); 86 using namespace std; 87 88 string workdir(pwd()); // remember current working directory (cwd). 89 90 // Checking that root_ exists and retrieve the absolute path to root_ 91 if (chdir(root_.c_str())) 92 throw runtime_error(string("svndigest: Root directory (") + root_ + 93 ") access failed."); 89 94 root_ = pwd(); 90 // remove trailing '/'91 if (*root_.rbegin()=='/')92 root_.erase(root_.begin()+root_.size()-1);93 chdir(workdir.c_str());94 95 95 // making targetdir absolute 96 chdir(targetdir_.c_str()); 96 // need to get back to cwd if relative paths are used. 97 if (chdir(workdir.c_str())) 98 runtime_error(string("svndigest: Failed to access cwd: ") + workdir); 99 100 // Checking that targetdir_ exists and retrieve the absolute path 101 // to targetdir_ 102 if (chdir(targetdir_.c_str())) 103 throw runtime_error(string("svndigest: Target directory (") + targetdir_ + 104 ") access failed."); 97 105 targetdir_ = pwd(); 98 // remove trailing '/'99 if ( *targetdir_.rbegin()=='/')100 root_.erase(targetdir_.begin()+targetdir_.size()-1);101 chdir(workdir.c_str());106 // Checking write permissions for targetdir_ 107 if (access_rights(targetdir_,"w")) 108 throw runtime_error(string("svndigest: No write permission on target ") + 109 "directory (" + targetdir_ +")."); 102 110 103 struct stat buf; 104 // check that root directory exists 105 if (stat(root_.c_str(),&buf)) 106 throw std::runtime_error("\nsvndigest: " + root_ + ": No such directory."); 107 108 // check that target directory exists 109 if (stat(targetdir_.c_str(),&buf)){ 110 throw std::runtime_error("\nsvndigest: " + targetdir_ + 111 ": No such directory."); 112 } 113 111 // return back to cwd 112 if (chdir(workdir.c_str())) 113 runtime_error(string("svndigest: Failed to access cwd: ") + workdir); 114 114 } 115 115 -
trunk/lib/utility.cc
r149 r151 27 27 #include <iostream> // remove this when 'blame' is removed 28 28 #include <sstream> 29 #include <stdexcept> 29 30 #include <string> 30 31 #include <sys/param.h> … … 33 34 namespace theplu{ 34 35 namespace svndigest{ 36 37 int access_rights(const std::string& path, const std::string& bits) 38 { 39 if (int value=access(path.c_str(),F_OK)) { 40 throw std::runtime_error(std::string("access_rights: ") + path + 41 "' does not exist."); 42 } 43 int mode=0; 44 for (u_int i=0; i<bits.length(); i++) 45 switch (bits[i]) { 46 case 'r': 47 mode|=R_OK; 48 break; 49 case 'w': 50 mode|=W_OK; 51 break; 52 case 'x': 53 mode|=X_OK; 54 break; 55 } 56 return access(path.c_str(),mode); 57 } 58 35 59 36 60 std::string file_name(const std::string& full_path) … … 41 65 return name; 42 66 } 67 43 68 44 69 void print_css(std::ostream& s) … … 130 155 { 131 156 char buffer[MAXPATHLEN]; 132 getcwd(buffer, MAXPATHLEN); 157 if (!getcwd(buffer, MAXPATHLEN)) 158 throw std::runtime_error("Failed to get current working directory"); 133 159 return std::string(buffer); 134 160 } 135 161 136 137 138 162 }} // end of namespace svndigest and namespace theplu -
trunk/lib/utility.h
r149 r151 36 36 namespace theplu{ 37 37 namespace svndigest{ 38 39 /// 40 /// @brief Check if access permissions match \a mode. \a mode must 41 /// be given as r, w, x, or combinations of these letters. 42 /// 43 /// @return On success (all requested permissions granted), zero 44 /// is returned. On error (at least one bit in mode asked for a 45 /// permission that is denied, or some other error occurred), -1 46 /// is returned, and errno is set appropriately. 47 /// 48 /// @throw An std::runtime_error is thrown when checking for write 49 /// permissions for a file/direcotry that does not exist. 50 /// 51 /// @see access(2) 52 /// 53 int access_rights(const std::string& path,const std::string& bits); 38 54 39 55 ///
Note: See TracChangeset
for help on using the changeset viewer.