Skip to content

FileManager "isDeletableFile" returns true when no file exists at path #1299

Open
@carlynorama

Description

@carlynorama

Here's a little sample program, but when I try to delete this file I would have expected it to throw on isDeletableFile because no file by that name exists.

swift-driver version: 1.120.5 Apple Swift version 6.1 (swiftlang-6.1.0.110.21 clang-1700.0.13.3)
Target: arm64-apple-macosx15.0

enum TestingErrors:Error {
    case fileNotDeletable
}

let arguments = CommandLine.arguments

print("you just ran \(arguments[0]) with the following commands: \(arguments.dropFirst())")

let instruction = arguments.dropFirst().first
let filename = arguments.dropFirst(2).first

try delete(path:"junkFileName.txt")


public func delete(path: String) throws {
    guard FileManager.default.isDeletableFile(atPath: path) else {
        throw TestingErrors.fileNotDeletable
    }
    
    print("MESSAGE:", "says it's deletable: \(path))")
    
    try FileManager.default.removeItem(atPath: path)
}

Actual error message:

you just ran .build/arm64-apple-macosx/debug/wrangle with the following commands: []
MESSAGE: says it's deletable: junkFileName.txt)
Swift/ErrorType.swift:253: Fatal error: Error raised at top level: Error Domain=NSCocoaErrorDomain Code=4 "“junkFileName.txt” couldn’t be removed." UserInfo={NSUserStringVariant=(
    Remove
), NSFilePath=junkFileName.txt, NSURL=junkFileName.txt -- file:///$MYUSERINFO/FileWrangler/, NSUnderlyingError=0x15b60f8f0 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}
zsh: trace trap  swift run

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions