Changeset 1207
- Timestamp:
- Mar 6, 2008, 12:56:42 AM (15 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/fileutil_test.cc
r1001 r1207 60 60 *error << "\trx permissions on " << file.path() << std::endl; 61 61 ok&=!testval; 62 if (!(testval=file.permissions("d"))) 63 *error << "\td permissions on " << file.path() << std::endl; 64 ok&=!testval; 62 65 } 63 66 catch (utility::IO_error e) { … … 85 88 *error << "\tw permission on " << file.path() << std::endl; 86 89 ok&=!testval; // 'w' on non-existent file ok if directory writeable 90 if (!(testval=file.permissions("d"))) 91 *error << "\td permission on " << file.path() << std::endl; 92 ok&=!testval; 87 93 } 88 94 catch (utility::IO_error e) { … … 109 115 *error << "\tw permission on " << file.path() << std::endl; 110 116 ok&=!testval; // 'w' on non-existent file ok if directory writeable 117 if (!(testval=file.permissions("d"))) 118 *error << "\td permission on " << file.path() << std::endl; 119 ok&=!testval; 111 120 } 112 121 catch (utility::IO_error e) { … … 134 143 *error << "\tw permission failed on " << file.path() << std::endl; 135 144 ok&=testval; 145 if (testval=file.permissions("d")) 146 *error << "\td permission failed on " << file.path() << std::endl; 147 ok&=testval; 136 148 } 137 149 catch (utility::IO_error e) { … … 160 172 } 161 173 174 try { 175 *error << "FileUtil Test 6" << std::endl; 176 utility::FileUtil file("fileutil_test.cc"); 177 file.permissions("rxwa"); // should throw 178 ok = false; 179 } 180 catch (std::invalid_argument& e) { 181 *error << "Expected exception thrown with what: " << e.what() << std::endl; 182 } 183 184 162 185 163 186 -
trunk/yat/utility/FileUtil.cc
r1001 r1207 28 28 #include <cerrno> 29 29 #include <iostream> 30 #include <stdexcept> 30 31 #include <string> 31 32 … … 54 55 55 56 int mode=0; 57 bool ok = true; 56 58 for (u_int i=0; i<bits.length(); i++) 57 59 switch (bits[i]) { 58 60 case 'r': 59 61 mode|=R_OK; 60 62 break; … … 65 67 mode|=X_OK; 66 68 break; 69 case 'd': 70 struct stat nodestat; 71 stat(tryme.c_str(),&nodestat); 72 if (!S_ISDIR(nodestat.st_mode)) 73 ok = false; 74 break; 75 default: 76 throw std::invalid_argument("FileUtil::permission: "+bits); 67 77 } 68 78 if (!ok) 79 return -1; 69 80 return access(tryme.c_str(),mode); 70 81 } -
trunk/yat/utility/FileUtil.h
r1000 r1207 56 56 /// 57 57 /// Check if access permissions match \a mode. \a mode must be 58 /// given as r, w, x, or combinations of these letters. The check59 /// is performed at tcall time.58 /// given as r, w, x, d, or combinations of these letters. The check 59 /// is performed at call time. 60 60 /// 61 61 /// \note Checking permissions on a non-existent file will match … … 69 69 /// is returned, and errno is set appropriately. 70 70 /// 71 /// \exception Throws whatever exists() throws. 71 /// \exception IO_error if exists() throws. 72 /// \exception std::invalid_argument if \a bits contain other 73 /// character than r, w, x, or d. 72 74 /// 73 75 int permissions(const std::string& bits) const; -
trunk/yat/utility/OptionFile.cc
r1179 r1207 68 68 throw cmd_error(ss.str()); 69 69 } 70 else if (*iter=='d' && fu.permissions("d")){ 71 std::stringstream ss; 72 ss << value() 73 << "': Not a directory"; 74 throw cmd_error(ss.str()); 75 } 70 76 } 71 77 std::stringstream ss;
Note: See TracChangeset
for help on using the changeset viewer.