Bug 1566700 - Add File.OS macRemoveXAttr. r=Yoric

Add functionality to remove an extended attribute from a file. This
functionality is currently MacOS specific due to that being the only use case we
currently have (see bug 1566523).

Differential Revision: https://phabricator.services.mozilla.com/D38523

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Bryce Van Dyk 2019-07-23 23:12:36 +00:00
Родитель f8907645db
Коммит 6b33621140
4 изменённых файлов: 59 добавлений и 0 удалений

Просмотреть файл

@ -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.
*

Просмотреть файл

@ -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);

Просмотреть файл

@ -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",

Просмотреть файл

@ -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();