显然,NSFileManager
无法删除由mkstemp()
. 下面是一些测试代码来证明这一点:
char pathCString[] = "/tmp/temp.XXXXXX";
int fileDescriptor = mkstemp(pathCString);
if (fileDescriptor == -1) {
NSLog(@"mkstemp failed");
} else {
close(fileDescriptor);
NSURL *url = [NSURL URLWithString:[NSString stringWithCString:pathCString encoding:NSASCIIStringEncoding]];
NSLog(@"URL: %@", url);
NSError *error;
if (![[NSFileManager defaultManager] removeItemAtURL:url error:&error]) {
NSLog(@"could not delete file: %@", error);
}
}
这是我在运行上述代码时在日志中看到的内容:
URL: /tmp/temp.A7DsLW
could not delete file: Error Domain=NSCocoaErrorDomain Code=4 UserInfo=0x1001108a0 "The file “temp.A7DsLW” doesn’t exist."
我在雪豹上运行这个。关于为什么会出现问题和/或如何解决问题的任何想法?
谢谢!