| 1281 | } |
| 1282 | |
| 1283 | bool FileModeGuard::Restore(std::string* emsg) |
| 1284 | { |
| 1285 | assert(filepath_.empty() == false); |
| 1286 | |
| 1287 | #ifndef _WIN32 |
| 1288 | struct stat file_stat; |
| 1289 | if (stat(filepath_.c_str(), &file_stat) != 0) { |
| 1290 | if (emsg) { |
| 1291 | *emsg = cmStrCat("Cannot get file stat: ", strerror(errno)); |
| 1292 | } |
| 1293 | return false; |
| 1294 | } |
| 1295 | |
| 1296 | // Nothing changed; everything is in the expected state |
| 1297 | if (file_stat.st_mode == mode_) { |
| 1298 | return true; |
| 1299 | } |
| 1300 | |
| 1301 | if (chmod(filepath_.c_str(), mode_) != 0) { |
| 1302 | if (emsg) { |
| 1303 | *emsg = cmStrCat("Cannot restore the file mode: ", strerror(errno)); |
| 1304 | } |
| 1305 | return false; |
| 1306 | } |
| 1307 | #else |
| 1308 | static_cast<void>(emsg); |
| 1309 | #endif |
| 1310 | |
| 1311 | return true; |
| 1312 | } |
| 1313 | |
| 1314 | bool FileModeGuard::HasErrors() const |
| 1315 | { |
no test coverage detected