My NSDocument subclass using a bundle document type which uses fileWrapperOfType:error: to write data to disk. This works perfectly but eventually it will start to save files with garbled names like "2_#$!@%!#_info.plist" instead of overwriting the proper file.
I don't know what changes to cause the problem but I think it's permissions related because Finder is not letting my write inside the bundle even though "stat" returns "drwxr-xr-x" which is writeable by the owner.
Did NSFileWrapper or NSDocument mess up the permissions or something? I'm new to this API but here is the code I'm using below (in Objective Pascal) which is hopefully readable by all.
function TScriptDocument.fileWrapperOfType_error (typeName: NSString; outError: NSErrorPtr): NSFileWrapper;
var
fileWrappers: NSDictionary;
propertiesFileWrapper: NSFileWrapper;
data: NSData;
propertiesName: NSString;
begin
if documentFileWrapper = nil then
documentFileWrapper := NSFileWrapper.alloc.initDirectoryWithFileWrappers(nil);
fileWrappers := documentFileWrapper.fileWrappers;
propertiesName := NSSTR('info.plist');
propertiesFileWrapper := fileWrappers.objectForKey(propertiesName);
if propertiesFileWrapper <> nil then
documentFileWrapper.removeFileWrapper(propertiesFileWrapper);
data := NSPropertyListSerialization.dataWithPropertyList_format_options_error(script.GetProperties, NSPropertyListXMLFormat_v1_0, 0, nil);
if data <> nil then
documentFileWrapper.addRegularFileWithContents_preferredFileName(data, propertiesName);
result := documentFileWrapper;
end;