Skip to content

Commit

Permalink
Allow deletion of file attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
nicklockwood committed Apr 28, 2022
1 parent 9a3dced commit f729f75
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions Viewer/Settings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,7 @@ final class Settings {
func set<T>(_ value: T?, for key: String, in document: Document,
andGlobally applyGlobally: Bool = false)
{
if let data = Data(value) {
try? document.fileURL?.setXattr(data, for: key.xattrName)
}
try? document.fileURL?.setXattr(Data(value), for: key.xattrName)
if applyGlobally {
// Set global default
defaults.set(value, forKey: key)
Expand Down Expand Up @@ -220,8 +218,12 @@ private extension URL {
}
}

func setXattr(_ data: Data, for name: String) throws {
func setXattr(_ data: Data?, for name: String) throws {
try withUnsafeFileSystemRepresentation { path in
guard let data = data else {
_ = removexattr(path, name, 0)
return
}
let length = data.count
let result = data.withUnsafeBytes {
setxattr(path, name, $0.baseAddress, length, 0, 0)
Expand Down

0 comments on commit f729f75

Please sign in to comment.