Overview
Comment: | OFFileManager: Add methods to get owner and mode |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
fdffe0a0e7c20cebba1124139aeee648 |
User & Date: | js on 2016-04-24 14:22:07 |
Other Links: | manifest | tags |
Context
2016-04-24
| ||
14:28 | OFFileManager: Documentation improvements check-in: a0ffd80bef user: js tags: trunk | |
14:22 | OFFileManager: Add methods to get owner and mode check-in: fdffe0a0e7 user: js tags: trunk | |
11:39 | Makefile: Revert back to packaging as .tar.gz check-in: 211234ea70 user: js tags: trunk | |
Changes
Modified src/OFFileManager.h from [9c6975a3f6] to [2ca910f374].
︙ | ︙ | |||
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | * returned * * @return The last status change time of the specified item */ - (OFDate*)statusChangeTimeOfItemAtPath: (OFString*)path; #ifdef OF_HAVE_CHMOD /*! * @brief Changes the permissions of an item. * * This method only changes the read-only flag on Windows. * * @param path The path to the item whose permissions should be changed * @param permissions The new permissions for the item */ - (void)changePermissionsOfItemAtPath: (OFString*)path permissions: (mode_t)permissions; #endif #ifdef OF_HAVE_CHOWN /*! * @brief Changes the owner of an item. * * This method is not available on some systems, most notably Windows. * * @param path The path to the item whose owner should be changed * @param owner The new owner for the item | > > > > > > > > > > > > > > > > > > > > | 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 | * returned * * @return The last status change time of the specified item */ - (OFDate*)statusChangeTimeOfItemAtPath: (OFString*)path; #ifdef OF_HAVE_CHMOD /*! * @brief Returns the permissions of the specified item. * * @param path The path to the item whose permissions should be returned * * @return The permissions of the specified item */ - (mode_t)permissionsOfItemAtPath: (OFString*)path; /*! * @brief Changes the permissions of an item. * * This method only changes the read-only flag on Windows. * * @param path The path to the item whose permissions should be changed * @param permissions The new permissions for the item */ - (void)changePermissionsOfItemAtPath: (OFString*)path permissions: (mode_t)permissions; #endif #ifdef OF_HAVE_CHOWN /*! * @brief Get the owner and group of the specified item. * * @param owner A pointer to an OFString* to store the owner, or nil * @param group A pointer to an OFString* to store the group, or nil * @param path The path to the item whose owner and group should be retrieved */ - (void)getOwner: (OFString *__autoreleasing _Nonnull *_Nullable)owner group: (OFString *__autoreleasing _Nonnull *_Nullable)group ofItemAtPath: (OFString*)path; /*! * @brief Changes the owner of an item. * * This method is not available on some systems, most notably Windows. * * @param path The path to the item whose owner should be changed * @param owner The new owner for the item |
︙ | ︙ |
Modified src/OFFileManager.m from [1ffcb630a2] to [75d768d86f].
︙ | ︙ | |||
32 33 34 35 36 37 38 | #import "OFFile.h" #import "OFString.h" #import "OFArray.h" #import "OFDate.h" #import "OFSystemInfo.h" #ifdef OF_HAVE_THREADS | | | 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | #import "OFFile.h" #import "OFString.h" #import "OFArray.h" #import "OFDate.h" #import "OFSystemInfo.h" #ifdef OF_HAVE_THREADS # import "OFMutex.h" #endif #import "OFChangeCurrentDirectoryPathFailedException.h" #import "OFChangeOwnerFailedException.h" #import "OFChangePermissionsFailedException.h" #import "OFCopyItemFailedException.h" #import "OFCreateDirectoryFailedException.h" |
︙ | ︙ | |||
77 78 79 80 81 82 83 | #define DEFAULT_MODE S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH #define DIR_MODE DEFAULT_MODE | S_IXUSR | S_IXGRP | S_IXOTH static OFFileManager *defaultManager; #if defined(OF_HAVE_CHOWN) && defined(OF_HAVE_THREADS) | | | | 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | #define DEFAULT_MODE S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH #define DIR_MODE DEFAULT_MODE | S_IXUSR | S_IXGRP | S_IXOTH static OFFileManager *defaultManager; #if defined(OF_HAVE_CHOWN) && defined(OF_HAVE_THREADS) static OFMutex *passwdMutex; #endif #if !defined(HAVE_READDIR_R) && !defined(OF_WINDOWS) && defined(OF_HAVE_THREADS) static OFMutex *readdirMutex; #endif int of_stat(OFString *path, of_stat_t *buffer) { #if defined(OF_WINDOWS) return _wstat64([path UTF16String], buffer); |
︙ | ︙ | |||
134 135 136 137 138 139 140 | /* * Make sure OFFile is initialized. * On some systems, this is needed to initialize the file system driver. */ [OFFile class]; #if defined(OF_HAVE_CHOWN) && defined(OF_HAVE_THREADS) | | < < < | < < | 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | /* * Make sure OFFile is initialized. * On some systems, this is needed to initialize the file system driver. */ [OFFile class]; #if defined(OF_HAVE_CHOWN) && defined(OF_HAVE_THREADS) passwdMutex = [[OFMutex alloc] init]; #endif #if !defined(HAVE_READDIR_R) && !defined(OF_WINDOWS) && defined(OF_HAVE_THREADS) readdirMutex = [[OFMutex alloc] init]; #endif defaultManager = [[OFFileManager alloc] init]; } + (OFFileManager*)defaultManager { |
︙ | ︙ | |||
299 300 301 302 303 304 305 | encoding = [OFSystemInfo native8BitEncoding]; if ((dir = opendir([path cStringWithEncoding: encoding])) == NULL) @throw [OFOpenItemFailedException exceptionWithPath: path errNo: errno]; # if !defined(HAVE_READDIR_R) && defined(OF_HAVE_THREADS) | | < < | 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 | encoding = [OFSystemInfo native8BitEncoding]; if ((dir = opendir([path cStringWithEncoding: encoding])) == NULL) @throw [OFOpenItemFailedException exceptionWithPath: path errNo: errno]; # if !defined(HAVE_READDIR_R) && defined(OF_HAVE_THREADS) [readdirMutex lock]; # endif @try { for (;;) { struct dirent *dirent; # ifdef HAVE_READDIR_R struct dirent buffer; # endif void *pool; |
︙ | ︙ | |||
348 349 350 351 352 353 354 | [files addObject: file]; objc_autoreleasePoolPop(pool); } } @finally { closedir(dir); # if !defined(HAVE_READDIR_R) && defined(OF_HAVE_THREADS) | | < | 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 | [files addObject: file]; objc_autoreleasePoolPop(pool); } } @finally { closedir(dir); # if !defined(HAVE_READDIR_R) && defined(OF_HAVE_THREADS) [readdirMutex unlock]; # endif } #else void *pool = objc_autoreleasePoolPush(); HANDLE handle; WIN32_FIND_DATAW fd; |
︙ | ︙ | |||
476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 | errNo: errno]; /* FIXME: We could be more precise on some OSes */ return [OFDate dateWithTimeIntervalSince1970: s.st_ctime]; } #ifdef OF_HAVE_CHMOD - (void)changePermissionsOfItemAtPath: (OFString*)path permissions: (mode_t)permissions { if (path == nil) @throw [OFInvalidArgumentException exception]; # ifndef OF_WINDOWS if (chmod([path cStringWithEncoding: [OFSystemInfo native8BitEncoding]], permissions) != 0) # else if (_wchmod([path UTF16String], permissions) != 0) # endif @throw [OFChangePermissionsFailedException exceptionWithPath: path permissions: permissions errNo: errno]; } #endif #ifdef OF_HAVE_CHOWN - (void)changeOwnerOfItemAtPath: (OFString*)path owner: (OFString*)owner group: (OFString*)group { uid_t uid = -1; gid_t gid = -1; of_string_encoding_t encoding; if (path == nil || (owner == nil && group == nil)) @throw [OFInvalidArgumentException exception]; encoding = [OFSystemInfo native8BitEncoding]; # ifdef OF_HAVE_THREADS | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > < < | | 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 | errNo: errno]; /* FIXME: We could be more precise on some OSes */ return [OFDate dateWithTimeIntervalSince1970: s.st_ctime]; } #ifdef OF_HAVE_CHMOD - (mode_t)permissionsOfItemAtPath: (OFString*)path { of_stat_t s; if (path == nil) @throw [OFInvalidArgumentException exception]; if (of_stat(path, &s) != 0) @throw [OFStatItemFailedException exceptionWithPath: path errNo: errno]; return s.st_mode; } - (void)changePermissionsOfItemAtPath: (OFString*)path permissions: (mode_t)permissions { if (path == nil) @throw [OFInvalidArgumentException exception]; # ifndef OF_WINDOWS if (chmod([path cStringWithEncoding: [OFSystemInfo native8BitEncoding]], permissions) != 0) # else if (_wchmod([path UTF16String], permissions) != 0) # endif @throw [OFChangePermissionsFailedException exceptionWithPath: path permissions: permissions errNo: errno]; } #endif #ifdef OF_HAVE_CHOWN - (void)getOwner: (OFString**)owner group: (OFString**)group ofItemAtPath: (OFString*)path { of_stat_t s; if (path == nil) @throw [OFInvalidArgumentException exception]; if (of_stat(path, &s) != 0) @throw [OFStatItemFailedException exceptionWithPath: path errNo: errno]; # ifdef OF_HAVE_THREADS [passwdMutex lock]; @try { # endif of_string_encoding_t encoding = [OFSystemInfo native8BitEncoding]; if (owner != nil) { struct passwd *passwd = getpwuid(s.st_uid); *owner = [OFString stringWithCString: passwd->pw_name encoding: encoding]; } if (group != nil) { struct group *group_ = getgrgid(s.st_gid); *group = [OFString stringWithCString: group_->gr_name encoding: encoding]; } # ifdef OF_HAVE_THREADS } @finally { [passwdMutex unlock]; } #endif } - (void)changeOwnerOfItemAtPath: (OFString*)path owner: (OFString*)owner group: (OFString*)group { uid_t uid = -1; gid_t gid = -1; of_string_encoding_t encoding; if (path == nil || (owner == nil && group == nil)) @throw [OFInvalidArgumentException exception]; encoding = [OFSystemInfo native8BitEncoding]; # ifdef OF_HAVE_THREADS [passwdMutex lock]; @try { # endif if (owner != nil) { struct passwd *passwd; if ((passwd = getpwnam([owner cStringWithEncoding: encoding])) == NULL) |
︙ | ︙ | |||
544 545 546 547 548 549 550 | group: group errNo: errno]; gid = group_->gr_gid; } # ifdef OF_HAVE_THREADS } @finally { | | < | 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 | group: group errNo: errno]; gid = group_->gr_gid; } # ifdef OF_HAVE_THREADS } @finally { [passwdMutex unlock]; } # endif if (chown([path cStringWithEncoding: encoding], uid, gid) != 0) @throw [OFChangeOwnerFailedException exceptionWithPath: path owner: owner group: group |
︙ | ︙ |