Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Sources/Commands/SwiftTool.swift
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,13 @@ public class SwiftTool {
// User didn't tell us to use these .netrc files so be more lenient with errors
func loadNetrcNoThrows(at path: AbsolutePath) -> NetrcAuthorizationProvider? {
guard localFileSystem.exists(path) else { return nil }

do {
try withTemporaryFile(dir: path.parentDirectory) { _ in }
} catch {
self.observabilityScope.emit(warning: "\(path.parentDirectory) is not accessible or not writable, not using .netrc file in it: \(error)")
return nil
}

do {
return try NetrcAuthorizationProvider(path: path, fileSystem: localFileSystem)
Expand Down
15 changes: 9 additions & 6 deletions Sources/Workspace/Workspace.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4085,9 +4085,10 @@ extension Workspace.Location {

// check that shared configuration directory is accessible, or warn + reset if not
if let sharedConfigurationDirectory = self.sharedConfigurationDirectory {
// it may not always be possible to create default location (for example de to restricted sandbox)
// It may not always be possible to create default location (for example de to restricted sandbox),
// in which case defaultDirectory would be nil.
let defaultDirectory = try? fileSystem.getOrCreateSwiftPMConfigurationDirectory(warningHandler: warningHandler)
if sharedConfigurationDirectory != defaultDirectory {
if defaultDirectory != nil, sharedConfigurationDirectory != defaultDirectory {
// custom location must be writable, throw if we cannot access it
try withTemporaryFile(dir: sharedConfigurationDirectory) { _ in }
} else {
Expand All @@ -4103,9 +4104,10 @@ extension Workspace.Location {

// check that shared configuration directory is accessible, or warn + reset if not
if let sharedSecurityDirectory = self.sharedSecurityDirectory {
// it may not always be possible to create default location (for example de to restricted sandbox)
// It may not always be possible to create default location (for example de to restricted sandbox),
// in which case defaultDirectory would be nil.
let defaultDirectory = try? fileSystem.getOrCreateSwiftPMSecurityDirectory()
if sharedSecurityDirectory != defaultDirectory {
if defaultDirectory != nil, sharedSecurityDirectory != defaultDirectory {
// custom location must be writable, throw if we cannot access it
try withTemporaryFile(dir: sharedSecurityDirectory) { _ in }
} else {
Expand All @@ -4121,9 +4123,10 @@ extension Workspace.Location {

// check that shared configuration directory is accessible, or warn + reset if not
if let sharedCacheDirectory = self.sharedCacheDirectory {
// it may not always be possible to create default location (for example de to restricted sandbox)
// It may not always be possible to create default location (for example de to restricted sandbox),
// in which case defaultDirectory would be nil.
let defaultDirectory = try? fileSystem.getOrCreateSwiftPMCacheDirectory()
if sharedCacheDirectory != defaultDirectory {
if defaultDirectory != nil, sharedCacheDirectory != defaultDirectory {
// custom location must be writable, throw if we cannot access it
try withTemporaryFile(dir: sharedCacheDirectory) { _ in }
} else {
Expand Down