Skip to content

Commit 4f03f1b

Browse files
committed
Make sure defaultDirectory is not nil before comparing sharedConfigurationDirectory
sharedConfigurationDirectory is a custom path iff defaultDirectory is non nil (in this case it's only ever nil when an error occurs while reading/writing the directory) and defaultDirectory != sharedConfigurationDirectory
1 parent 07b0fb5 commit 4f03f1b

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

Sources/Workspace/Workspace.swift

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4085,9 +4085,10 @@ extension Workspace.Location {
40854085

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

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

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

0 commit comments

Comments
 (0)