Bug 1772089 p3: Remove content temp dir from PathUtils. r=barret

This changes tempDir to be the OS temp to prevent churn, because it has many
more uses than osTempDir.

Differential Revision: https://phabricator.services.mozilla.com/D168594
This commit is contained in:
Bob Owen 2023-02-24 08:44:41 +00:00
parent 219f299719
commit c06ee8016f
12 changed files with 13 additions and 66 deletions

View File

@ -80,7 +80,7 @@ async function cropAndCompare(window, src, expected, test, region, subregions) {
add_task(async function crop() {
const window = Services.wm.getMostRecentWindow("navigator:browser");
const tmp = PathUtils.osTempDir;
const tmp = PathUtils.tempDir;
is(
await cropAndCompare(
window,

View File

@ -28,7 +28,7 @@ ChromeUtils.defineESModuleGetters(lazy, {
});
function getHeapSnapshotFileTemplate() {
return PathUtils.join(PathUtils.osTempDir, `${Date.now()}.fxsnapshot`);
return PathUtils.join(PathUtils.tempDir, `${Date.now()}.fxsnapshot`);
}
/**
@ -63,7 +63,7 @@ exports.getHeapSnapshotTempFilePath = function(snapshotId) {
if (!isValidSnapshotFileId(snapshotId)) {
return null;
}
return PathUtils.join(PathUtils.osTempDir, snapshotId + ".fxsnapshot");
return PathUtils.join(PathUtils.tempDir, snapshotId + ".fxsnapshot");
};
/**

View File

@ -124,17 +124,11 @@ partial namespace PathUtils {
readonly attribute DOMString localProfileDir;
/**
* The temporary directory for the process.
* The OS temporary directory.
*/
[Throws, BinaryName="TempDirSync"]
readonly attribute DOMString tempDir;
/**
* The OS temporary directory.
*/
[Throws, BinaryName="OSTempDirSync"]
readonly attribute DOMString osTempDir;
/**
* The libxul path.
*/
@ -157,17 +151,11 @@ partial namespace PathUtils {
Promise<DOMString> getLocalProfileDir();
/**
* The temporary directory for the process.
* The OS temporary directory.
*/
[NewObject, BinaryName="GetTempDirAsync"]
Promise<DOMString> getTempDir();
/**
* The OS temporary directory.
*/
[NewObject, BinaryName="GetOSTempDirAsync"]
Promise<DOMString> getOSTempDir();
/**
* The libxul path.
*/

View File

@ -440,15 +440,6 @@ void PathUtils::GetTempDirSync(const GlobalObject&, nsString& aResult,
.GetDirectorySync(aResult, aErr, DirectoryCache::Directory::Temp);
}
void PathUtils::GetOSTempDirSync(const GlobalObject&, nsString& aResult,
ErrorResult& aErr) {
MOZ_ASSERT(NS_IsMainThread());
auto guard = sDirCache.Lock();
DirectoryCache::Ensure(guard.ref())
.GetDirectorySync(aResult, aErr, DirectoryCache::Directory::OSTemp);
}
void PathUtils::GetXulLibraryPathSync(const GlobalObject&, nsString& aResult,
ErrorResult& aErr) {
MOZ_ASSERT(NS_IsMainThread());
@ -486,15 +477,6 @@ already_AddRefed<Promise> PathUtils::GetTempDirAsync(
.GetDirectoryAsync(aGlobal, aErr, DirectoryCache::Directory::Temp);
}
already_AddRefed<Promise> PathUtils::GetOSTempDirAsync(
const GlobalObject& aGlobal, ErrorResult& aErr) {
MOZ_ASSERT(!NS_IsMainThread());
auto guard = sDirCache.Lock();
return DirectoryCache::Ensure(guard.ref())
.GetDirectoryAsync(aGlobal, aErr, DirectoryCache::Directory::OSTemp);
}
already_AddRefed<Promise> PathUtils::GetXulLibraryPathAsync(
const GlobalObject& aGlobal, ErrorResult& aErr) {
MOZ_ASSERT(!NS_IsMainThread());

View File

@ -93,8 +93,6 @@ class PathUtils final {
ErrorResult& aErr);
static void GetTempDirSync(const GlobalObject&, nsString& aResult,
ErrorResult& aErr);
static void GetOSTempDirSync(const GlobalObject&, nsString& aResult,
ErrorResult& aErr);
static void GetXulLibraryPathSync(const GlobalObject&, nsString& aResult,
ErrorResult& aErr);
@ -104,8 +102,6 @@ class PathUtils final {
const GlobalObject& aGlobal, ErrorResult& aErr);
static already_AddRefed<Promise> GetTempDirAsync(const GlobalObject& aGlobal,
ErrorResult& aErr);
static already_AddRefed<Promise> GetOSTempDirAsync(
const GlobalObject& aGlobal, ErrorResult& aErr);
static already_AddRefed<Promise> GetXulLibraryPathAsync(
const GlobalObject& aGlobal, ErrorResult& aErr);
@ -134,14 +130,10 @@ class PathUtils::DirectoryCache final {
* The user's local profile directory.
*/
LocalProfile,
/**
* The temporary directory for the process.
*/
Temp,
/**
* The OS temporary directory.
*/
OSTemp,
Temp,
/**
* The libxul path.
*/
@ -255,8 +247,9 @@ class PathUtils::DirectoryCache final {
DirectoryArray<MozPromiseHolder<PopulateDirectoriesPromise>> mPromises;
static constexpr DirectoryArray<const char*> kDirectoryNames{
NS_APP_USER_PROFILE_50_DIR, NS_APP_USER_PROFILE_LOCAL_50_DIR,
NS_APP_CONTENT_PROCESS_TEMP_DIR, NS_OS_TEMP_DIR,
NS_APP_USER_PROFILE_50_DIR,
NS_APP_USER_PROFILE_LOCAL_50_DIR,
NS_OS_TEMP_DIR,
NS_XPCOM_LIBRARY_FILE,
};
};

View File

@ -33,12 +33,5 @@ self.onmessage = async function(message) {
"PathUtils.getTempDir() in a worker should match PathUtils.tempDir on main thread"
);
const osTempDir = await PathUtils.getOSTempDir();
is(
osTempDir,
expected.osTempDir,
"PathUtils.getOSTempDir() in a worker should match PathUtils.osTempDir on main thread"
);
finish();
};

View File

@ -585,8 +585,7 @@
const tests = [
["profileDir", "ProfD"],
["localProfileDir", "ProfLD"],
["tempDir", AppConstants.MOZ_SANDBOX ? "ContentTmpD" : "TmpD"],
["osTempDir", "TmpD"],
["tempDir", "TmpD"],
];
for (const [attrName, dirConstant] of tests) {

View File

@ -23,7 +23,6 @@
profileDir: PathUtils.profileDir,
localProfileDir: PathUtils.localProfileDir,
tempDir: PathUtils.tempDir,
osTempDir: PathUtils.osTempDir,
});
info("test_pathtuils_worker.xhtml: Test running...");

View File

@ -1517,13 +1517,6 @@ XPCShellDirProvider::GetFile(const char* prop, bool* persistent,
file.forget(result);
return NS_OK;
}
#ifdef MOZ_SANDBOX
if (!strcmp(prop, NS_APP_CONTENT_PROCESS_TEMP_DIR)) {
// Forward to the OS Temp directory
*persistent = true;
return NS_GetSpecialDirectory(NS_OS_TEMP_DIR, result);
}
#endif
return NS_ERROR_FAILURE;
}

View File

@ -526,7 +526,7 @@ add_task(async function test_subprocess_pathSearch() {
add_task(async function test_subprocess_workdir() {
let procDir = Services.dirsvc.get("CurWorkD", Ci.nsIFile).path;
let tmpDir = PathUtils.normalize(PathUtils.osTempDir);
let tmpDir = PathUtils.normalize(PathUtils.tempDir);
notEqual(
procDir,

View File

@ -6,7 +6,7 @@ const PYTHON_BIN = PathUtils.filename(PYTHON);
const PYTHON_DIR = PathUtils.parent(PYTHON);
const DOES_NOT_EXIST = PathUtils.join(
PathUtils.osTempDir,
PathUtils.tempDir,
"ThisPathDoesNotExist"
);

View File

@ -419,7 +419,7 @@ function downloadFile(url, options = { httpsOnlyNoUpgrade: false }) {
}
(async function() {
const path = await IOUtils.createUniqueFile(
PathUtils.osTempDir,
PathUtils.tempDir,
"tmpaddon"
);
logger.info(`Downloaded file will be saved to ${path}`);