| 1291 | |
| 1292 | |
| 1293 | void Archive::ConvertAttributes() |
| 1294 | { |
| 1295 | #if defined(_WIN_ALL) || defined(_EMX) |
| 1296 | if (FileHead.HSType!=HSYS_WINDOWS) |
| 1297 | FileHead.FileAttr=FileHead.Dir ? 0x10 : 0x20; |
| 1298 | #endif |
| 1299 | #ifdef _UNIX |
| 1300 | // umask defines which permission bits must not be set by default |
| 1301 | // when creating a file or directory. The typical default value |
| 1302 | // for the process umask is S_IWGRP | S_IWOTH (octal 022), |
| 1303 | // resulting in 0644 mode for new files. |
| 1304 | // Normally umask is applied automatically when creating a file, |
| 1305 | // but we set attributes with chmod later, so we need to calculate |
| 1306 | // resulting attributes here. We do it only for non-Unix archives. |
| 1307 | // We restore native Unix attributes as is, because it can be backup. |
| 1308 | static mode_t mask = (mode_t) -1; |
| 1309 | |
| 1310 | if (mask == (mode_t) -1) |
| 1311 | { |
| 1312 | // umask call returns the current umask value. Argument (022) is not |
| 1313 | // really important here. |
| 1314 | mask = umask(022); |
| 1315 | |
| 1316 | // Restore the original umask value, which was changed to 022 above. |
| 1317 | umask(mask); |
| 1318 | } |
| 1319 | |
| 1320 | switch(FileHead.HSType) |
| 1321 | { |
| 1322 | case HSYS_WINDOWS: |
| 1323 | { |
| 1324 | // Mapping MSDOS, OS/2 and Windows file attributes to Unix. |
| 1325 | |
| 1326 | if (FileHead.FileAttr & 0x10) // FILE_ATTRIBUTE_DIRECTORY |
| 1327 | { |
| 1328 | // For directories we use 0777 mask. |
| 1329 | FileHead.FileAttr=0777 & ~mask; |
| 1330 | } |
| 1331 | else |
| 1332 | if (FileHead.FileAttr & 1) // FILE_ATTRIBUTE_READONLY |
| 1333 | { |
| 1334 | // For read only files we use 0444 mask with 'w' bits turned off. |
| 1335 | FileHead.FileAttr=0444 & ~mask; |
| 1336 | } |
| 1337 | else |
| 1338 | { |
| 1339 | // umask does not set +x for regular files, so we use 0666 |
| 1340 | // instead of 0777 as for directories. |
| 1341 | FileHead.FileAttr=0666 & ~mask; |
| 1342 | } |
| 1343 | } |
| 1344 | break; |
| 1345 | case HSYS_UNIX: |
| 1346 | break; |
| 1347 | default: |
| 1348 | if (FileHead.Dir) |
| 1349 | FileHead.FileAttr=0x41ff & ~mask; |
| 1350 | else |
no outgoing calls
no test coverage detected