Skip to content

Commit da7400e

Browse files
committed
Tar: Fix permissions (owner should have write permission)
The owner needs write permission to be able to delete the files after unpacking the archive.
1 parent 0a99dc4 commit da7400e

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

Sources/Tar/tar.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -419,14 +419,14 @@ extension Archive {
419419
/// - prefix: Path prefix
420420
/// - data: File contents
421421
public func appendFile(name: String, prefix: String = "", data: [UInt8]) throws {
422-
try append(.init(header: .init(name: name, size: data.count, prefix: prefix), data: data))
422+
try append(.init(header: .init(name: name, mode: 0o755, size: data.count, prefix: prefix), data: data))
423423
}
424424

425425
/// Adds a new directory member at the end of the archive
426426
/// parameters:
427427
/// - name: Directory name
428428
/// - prefix: Path prefix
429429
public func appendDirectory(name: String, prefix: String = "") throws {
430-
try append(.init(header: .init(name: name, typeflag: .DIRTYPE, prefix: prefix)))
430+
try append(.init(header: .init(name: name, mode: 0o755, typeflag: .DIRTYPE, prefix: prefix)))
431431
}
432432
}

Tests/TarTests/TarUnitTests.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ let trailer = [UInt8](repeating: 0, count: trailerSize)
277277
0, 0, 0, 0,
278278

279279
// mode: 8 bytes
280-
48, 48, 48, 53, 53, 53, 32, 0,
280+
48, 48, 48, 55, 53, 53, 32, 0,
281281

282282
// uid: 8 bytes
283283
48, 48, 48, 48, 48, 48, 32, 0,
@@ -292,7 +292,7 @@ let trailer = [UInt8](repeating: 0, count: trailerSize)
292292
48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 32,
293293

294294
// chksum: 8 bytes
295-
48, 49, 49, 48, 55, 53, 0, 32,
295+
48, 49, 49, 48, 55, 55, 0, 32,
296296

297297
// typeflag: 1 byte
298298
48,
@@ -360,7 +360,7 @@ let trailer = [UInt8](repeating: 0, count: trailerSize)
360360
0, 0, 0, 0,
361361

362362
// mode: 8 bytes
363-
48, 48, 48, 53, 53, 53, 32, 0,
363+
48, 48, 48, 55, 53, 53, 32, 0,
364364

365365
// uid: 8 bytes
366366
48, 48, 48, 48, 48, 48, 32, 0,
@@ -375,7 +375,7 @@ let trailer = [UInt8](repeating: 0, count: trailerSize)
375375
48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 32,
376376

377377
// chksum: 8 bytes
378-
48, 49, 49, 48, 52, 55, 0, 32,
378+
48, 49, 49, 48, 53, 49, 0, 32,
379379

380380
// typeflag: 1 byte
381381
48,
@@ -476,7 +476,7 @@ let trailer = [UInt8](repeating: 0, count: trailerSize)
476476
0, 0, 0, 0,
477477

478478
// mode: 8 bytes
479-
48, 48, 48, 53, 53, 53, 32, 0,
479+
48, 48, 48, 55, 53, 53, 32, 0,
480480

481481
// uid: 8 bytes
482482
48, 48, 48, 48, 48, 48, 32, 0,
@@ -491,7 +491,7 @@ let trailer = [UInt8](repeating: 0, count: trailerSize)
491491
48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 32,
492492

493493
// chksum: 8 bytes
494-
48, 49, 50, 51, 50, 54, 0, 32,
494+
48, 49, 50, 51, 51, 48, 0, 32,
495495

496496
// typeflag: 1 byte
497497
53,

0 commit comments

Comments
 (0)