Commit d01bd2f
committed
Create a file with permissions that respects umask
**Problem**
`Data.write(to:)` is a only method in the Foundation that can create a
regular file.
However, it ignores `umask` and always set 0600 permission unlike
macOS Foundation, which respects process `umask`.
**Solution**
1. With `.atomic` write option
It uses `mkstemp(3)` in `_NSCreateTemporaryFile`, which is always
creating a file with 0600 permission, if the system follows
the latest POSIX specification or the permission is undefined.
On macOS Foundation, therefore `_NSCreateTemporaryFile` uses
`mktemp(3)` and `open(2)` instead to respect `umask`.
2. Without `.atomic` write option
It uses `0o600` even if it uses `open(2)` that respects `umask`.
Simply gives `0o666` instead.
This is a bug caused by previous commit in
#1876.
Swift JIRA is https://bugs.swift.org/browse/SR-13307.1 parent 0ded41e commit d01bd2f
File tree
3 files changed
+74
-6
lines changed- Sources/Foundation
- Tests/Foundation/Tests
3 files changed
+74
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
434 | 434 | | |
435 | 435 | | |
436 | 436 | | |
437 | | - | |
438 | | - | |
| 437 | + | |
439 | 438 | | |
440 | 439 | | |
441 | 440 | | |
| |||
446 | 445 | | |
447 | 446 | | |
448 | 447 | | |
449 | | - | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
450 | 451 | | |
451 | 452 | | |
452 | 453 | | |
| |||
457 | 458 | | |
458 | 459 | | |
459 | 460 | | |
460 | | - | |
461 | | - | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
462 | 467 | | |
463 | 468 | | |
464 | 469 | | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
465 | 473 | | |
466 | 474 | | |
467 | 475 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
760 | 760 | | |
761 | 761 | | |
762 | 762 | | |
763 | | - | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
764 | 767 | | |
765 | 768 | | |
766 | 769 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
10 | 20 | | |
11 | 21 | | |
12 | 22 | | |
| |||
223 | 233 | | |
224 | 234 | | |
225 | 235 | | |
| 236 | + | |
| 237 | + | |
226 | 238 | | |
227 | 239 | | |
228 | 240 | | |
| |||
551 | 563 | | |
552 | 564 | | |
553 | 565 | | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
554 | 611 | | |
555 | 612 | | |
556 | 613 | | |
| |||
0 commit comments