diff --git a/toolkit/components/osfile/modules/osfile_async_front.jsm b/toolkit/components/osfile/modules/osfile_async_front.jsm index 94c27c75f243..218cdbbf1454 100644 --- a/toolkit/components/osfile/modules/osfile_async_front.jsm +++ b/toolkit/components/osfile/modules/osfile_async_front.jsm @@ -1114,6 +1114,27 @@ File.remove = function remove(path, options) { return Scheduler.post("remove", [Type.path.toMsg(path), options], path); }; +// Extended attribute functions are MacOS only at this point. +if (SharedAll.Constants.Sys.Name == "Darwin") { + /** + * Remove an extended attribute (xattr) from a file. + * + * @param {string} path The name of the file. + * @param {string} name The name of the extended attribute. + * + * @returns {promise} + * @resolves {null} + * @rejects {OS.File.Error} In case of an I/O error. + */ + File.macRemoveXAttr = function macRemoveXAttr(path, name) { + return Scheduler.post( + "macRemoveXAttr", + [Type.path.toMsg(path), Type.cstring.toMsg(name)], + [path, name] + ); + }; +} + /** * Create a directory and, optionally, its parent directories. * diff --git a/toolkit/components/osfile/modules/osfile_async_worker.js b/toolkit/components/osfile/modules/osfile_async_worker.js index 034e94539d7a..b381bcb7d7e9 100644 --- a/toolkit/components/osfile/modules/osfile_async_worker.js +++ b/toolkit/components/osfile/modules/osfile_async_worker.js @@ -285,6 +285,12 @@ if (this.Components) { removeDir(path, options) { return File.removeDir(Type.path.fromMsg(path), options); }, + macRemoveXAttr(path, name) { + return File.macRemoveXAttr( + Type.path.fromMsg(path), + Type.cstring.fromMsg(name) + ); + }, new_DirectoryIterator: function new_DirectoryIterator(path, options) { let directoryPath = Type.path.fromMsg(path); let iterator = new File.DirectoryIterator(directoryPath, options); diff --git a/toolkit/components/osfile/modules/osfile_unix_back.jsm b/toolkit/components/osfile/modules/osfile_unix_back.jsm index 4e45c3c6ecaa..5776ce2b690a 100644 --- a/toolkit/components/osfile/modules/osfile_unix_back.jsm +++ b/toolkit/components/osfile/modules/osfile_unix_back.jsm @@ -692,6 +692,20 @@ ); // Other Unices } + if (OS.Constants.Sys.Name == "Darwin") { + // At the time of writing we only need this on MacOS. + libc.declareLazyFFI( + SysFile, + "removexattr", + "removexattr", + ctypes.default_abi, + /* return*/ Type.negativeone_or_nothing, + Type.path, + Type.cstring, + Type.int + ); + } + libc.declareLazyFFI( SysFile, "rename", diff --git a/toolkit/components/osfile/modules/osfile_unix_front.jsm b/toolkit/components/osfile/modules/osfile_unix_front.jsm index 76923b864bc9..2179c8eae08a 100644 --- a/toolkit/components/osfile/modules/osfile_unix_front.jsm +++ b/toolkit/components/osfile/modules/osfile_unix_front.jsm @@ -916,6 +916,24 @@ return serialized; }; + // Extended attribute functions are MacOS only at this point. + if (OS.Constants.Sys.Name == "Darwin") { + /** + * Remove an extended attribute (xattr) from a file. + * + * @param {string} path The name of the file. + * @param {string} name The name of the extended attribute. + * + * @throws {OS.File.Error} In case of an I/O error. + */ + File.macRemoveXAttr = function removexattr(path, name) { + let result = UnixFile.removexattr(path, name, 0 /* follow links */); + if (result == -1) { + throw new File.Error("removexattr", ctypes.errno, path); + } + }; + } + let gStatData = new Type.stat.implementation(); let gStatDataPtr = gStatData.address();