Skip to content

Commit

Permalink
Allow to write into stdout by removing atomic write on macos
Browse files Browse the repository at this point in the history
  • Loading branch information
e-marchand committed Nov 6, 2022
1 parent 8de4449 commit 344700f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
23 changes: 13 additions & 10 deletions Sources/PropertyList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ open class PropertyList {
lineEnding: String? = nil,
atomic: Bool = true) throws {
let format = format ?? .xml
#if os(Linux)
let writingOptions: Data.WritingOptions = []
#else
let writingOptions: Data.WritingOptions = atomic && !url.isStdOut ? [.atomicWrite]: []
#endif
if format == .openStep {
try XcodeProj(dict: self.dict, format: Format.openStep).write(to: url,
format: format,
Expand All @@ -123,18 +128,10 @@ open class PropertyList {
fromPropertyList: dict,
format: propertyListformat,
options: 0)
#if os(Linux)
try data.write(to: url, options: []) // error no attomic on linux
#else
try data.write(to: url, options: atomic ? [.atomicWrite] : [])
#endif
try data.write(to: url, options: writingOptions)
} else if format == .json {
let data = try JSONSerialization.data(withJSONObject: dict, options: .prettyPrinted)
#if os(Linux)
try data.write(to: url, options: []) // error no attomic on linux
#else
try data.write(to: url, options: atomic ? [.atomicWrite] : [])
#endif
try data.write(to: url, options: writingOptions)
}
}

Expand All @@ -150,3 +147,9 @@ open class PropertyList {
}

}

extension URL {
var isStdOut: Bool {
return self.isFileURL && self.path == "/dev/stdout"
}
}
8 changes: 7 additions & 1 deletion Sources/XcodeProj.swift
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,13 @@ public class XcodeProj: PropertyList {
let format = format ?? self.format
if format == .openStep {
let serializer = OpenStepSerializer(projectName: name, lineEnding: lineEnding, projectFile: self)
try serializer.serialize().write(to: pbxprojURL, atomically: atomic, encoding: .utf8)
let string = try serializer.serialize()
#if os(Linux)
let atomically = false
#else
let atomically = atomic && !pbxprojURL.isStdOut
#endif
try string.write(to: pbxprojURL, atomically: atomically, encoding: .utf8)
} else {
try super.write(to: pbxprojURL,
format: format,
Expand Down

0 comments on commit 344700f

Please sign in to comment.