Differences From Artifact [c320611d8a]:
- File src/OFFile.m — part of check-in [813c00ccf0] at 2013-01-09 22:24:47 on branch trunk — Update copyright. (user: js, size: 18500) [annotate] [blame] [check-ins using]
To Artifact [25d73bc7b8]:
- File
src/OFFile.m
— part of check-in
[9ddd33a258]
at
2013-01-12 17:29:24
on branch trunk
— Rename *UsingEncoding: to *WithEncoding:.
This reverts 5362941.
Even though *UsingEncoding: is what Foundation uses, *WithEncoding: is
more natural and is more consistent with the rest. Also, this means this
restores it to the API of 0.7. (user: js, size: 18480) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
211 212 213 214 215 216 217 | } + (BOOL)fileExistsAtPath: (OFString*)path { #ifndef _WIN32 struct stat s; | | | | | 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 | } + (BOOL)fileExistsAtPath: (OFString*)path { #ifndef _WIN32 struct stat s; if (stat([path cStringWithEncoding: OF_STRING_ENCODING_NATIVE], &s) == -1) return NO; #else struct _stat s; if (_wstat([path UTF16String], &s) == -1) return NO; #endif if (S_ISREG(s.st_mode)) return YES; return NO; } + (BOOL)directoryExistsAtPath: (OFString*)path { #ifndef _WIN32 struct stat s; if (stat([path cStringWithEncoding: OF_STRING_ENCODING_NATIVE], &s) == -1) return NO; #else struct _stat s; if (_wstat([path UTF16String], &s) == -1) return NO; #endif if (S_ISDIR(s.st_mode)) return YES; return NO; } + (void)createDirectoryAtPath: (OFString*)path { #ifndef _WIN32 if (mkdir([path cStringWithEncoding: OF_STRING_ENCODING_NATIVE], DIR_MODE)) #else if (_wmkdir([path UTF16String])) #endif @throw [OFCreateDirectoryFailedException exceptionWithClass: self path: path]; |
︙ | ︙ | |||
309 310 311 312 313 314 315 | { OFMutableArray *files = [OFMutableArray array]; #ifndef _WIN32 DIR *dir; struct dirent *dirent; | | | 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 | { OFMutableArray *files = [OFMutableArray array]; #ifndef _WIN32 DIR *dir; struct dirent *dirent; if ((dir = opendir([path cStringWithEncoding: OF_STRING_ENCODING_NATIVE])) == NULL) @throw [OFOpenFileFailedException exceptionWithClass: self path: path mode: @"r"]; @try { while ((dirent = readdir(dir)) != NULL) { |
︙ | ︙ | |||
376 377 378 379 380 381 382 | return files; } + (void)changeToDirectoryAtPath: (OFString*)path { #ifndef _WIN32 | | | | 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 | return files; } + (void)changeToDirectoryAtPath: (OFString*)path { #ifndef _WIN32 if (chdir([path cStringWithEncoding: OF_STRING_ENCODING_NATIVE])) #else if (_wchdir([path UTF16String])) #endif @throw [OFChangeDirectoryFailedException exceptionWithClass: self path: path]; } #ifndef _PSP + (void)changeModeOfFileAtPath: (OFString*)path mode: (mode_t)mode { # ifndef _WIN32 if (chmod([path cStringWithEncoding: OF_STRING_ENCODING_NATIVE], mode)) @throw [OFChangeFileModeFailedException exceptionWithClass: self path: path mode: mode]; # else DWORD attributes = GetFileAttributesW([path UTF16String]); |
︙ | ︙ | |||
423 424 425 426 427 428 429 | #endif + (off_t)sizeOfFileAtPath: (OFString*)path { #ifndef _WIN32 struct stat s; | | | | 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 | #endif + (off_t)sizeOfFileAtPath: (OFString*)path { #ifndef _WIN32 struct stat s; if (stat([path cStringWithEncoding: OF_STRING_ENCODING_NATIVE], &s) == -1) #else struct _stat s; if (_wstat([path UTF16String], &s) == -1) #endif /* FIXME: Maybe use another exception? */ @throw [OFOpenFileFailedException exceptionWithClass: self path: path mode: @"r"]; return s.st_size; } + (OFDate*)modificationDateOfFileAtPath: (OFString*)path { #ifndef _WIN32 struct stat s; if (stat([path cStringWithEncoding: OF_STRING_ENCODING_NATIVE], &s) == -1) #else struct _stat s; if (_wstat([path UTF16String], &s) == -1) #endif /* FIXME: Maybe use another exception? */ |
︙ | ︙ | |||
480 481 482 483 484 485 486 | @throw [OFLockFailedException exceptionWithClass: self]; @try { # endif if (owner != nil) { struct passwd *passwd; | | | | | 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 | @throw [OFLockFailedException exceptionWithClass: self]; @try { # endif if (owner != nil) { struct passwd *passwd; if ((passwd = getpwnam([owner cStringWithEncoding: OF_STRING_ENCODING_NATIVE])) == NULL) @throw [OFChangeFileOwnerFailedException exceptionWithClass: self path: path owner: owner group: group]; uid = passwd->pw_uid; } if (group != nil) { struct group *group_; if ((group_ = getgrnam([group cStringWithEncoding: OF_STRING_ENCODING_NATIVE])) == NULL) @throw [OFChangeFileOwnerFailedException exceptionWithClass: self path: path owner: owner group: group]; gid = group_->gr_gid; } # ifdef OF_THREADS } @finally { if (!of_mutex_unlock(&mutex)) @throw [OFUnlockFailedException exceptionWithClass: self]; } # endif if (chown([path cStringWithEncoding: OF_STRING_ENCODING_NATIVE], uid, gid)) @throw [OFChangeFileOwnerFailedException exceptionWithClass: self path: path owner: owner group: group]; } |
︙ | ︙ | |||
591 592 593 594 595 596 597 | if ([self directoryExistsAtPath: destination]) { OFString *filename = [source lastPathComponent]; destination = [OFString stringWithPath: destination, filename, nil]; } #ifndef _WIN32 | | | | | | | | | | 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 | if ([self directoryExistsAtPath: destination]) { OFString *filename = [source lastPathComponent]; destination = [OFString stringWithPath: destination, filename, nil]; } #ifndef _WIN32 if (rename([source cStringWithEncoding: OF_STRING_ENCODING_NATIVE], [destination cStringWithEncoding: OF_STRING_ENCODING_NATIVE])) #else if (!MoveFileW([source UTF16String], [destination UTF16String])) #endif @throw [OFRenameFileFailedException exceptionWithClass: self sourcePath: source destinationPath: destination]; objc_autoreleasePoolPop(pool); } + (void)deleteFileAtPath: (OFString*)path { #ifndef _WIN32 if (unlink([path cStringWithEncoding: OF_STRING_ENCODING_NATIVE])) #else if (_wunlink([path UTF16String])) #endif @throw [OFDeleteFileFailedException exceptionWithClass: self path: path]; } + (void)deleteDirectoryAtPath: (OFString*)path { #ifndef _WIN32 if (rmdir([path cStringWithEncoding: OF_STRING_ENCODING_NATIVE])) #else if (_wrmdir([path UTF16String])) #endif @throw [OFDeleteDirectoryFailedException exceptionWithClass: self path: path]; } #ifndef _WIN32 + (void)linkFileAtPath: (OFString*)source toPath: (OFString*)destination { void *pool = objc_autoreleasePoolPush(); if ([self directoryExistsAtPath: destination]) { OFString *filename = [source lastPathComponent]; destination = [OFString stringWithPath: destination, filename, nil]; } if (link([source cStringWithEncoding: OF_STRING_ENCODING_NATIVE], [destination cStringWithEncoding: OF_STRING_ENCODING_NATIVE]) != 0) @throw [OFLinkFailedException exceptionWithClass: self sourcePath: source destinationPath: destination]; objc_autoreleasePoolPop(pool); } #endif #if !defined(_WIN32) && !defined(_PSP) + (void)symlinkFileAtPath: (OFString*)source toPath: (OFString*)destination { void *pool = objc_autoreleasePoolPush(); if ([self directoryExistsAtPath: destination]) { OFString *filename = [source lastPathComponent]; destination = [OFString stringWithPath: destination, filename, nil]; } if (symlink([source cStringWithEncoding: OF_STRING_ENCODING_NATIVE], [destination cStringWithEncoding: OF_STRING_ENCODING_NATIVE]) != 0) @throw [OFSymlinkFailedException exceptionWithClass: self sourcePath: source destinationPath: destination]; objc_autoreleasePoolPop(pool); } |
︙ | ︙ | |||
697 698 699 700 701 702 703 | if ((flags = parse_mode([mode UTF8String])) == -1) @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; #ifndef _WIN32 | | | 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 | if ((flags = parse_mode([mode UTF8String])) == -1) @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; #ifndef _WIN32 if ((fd = open([path cStringWithEncoding: OF_STRING_ENCODING_NATIVE], flags, DEFAULT_MODE)) == -1) #else if ((fd = _wopen([path UTF16String], flags, DEFAULT_MODE)) == -1) #endif @throw [OFOpenFileFailedException exceptionWithClass: [self class] |
︙ | ︙ |