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() { add_task(async function crop() {
const window = Services.wm.getMostRecentWindow("navigator:browser"); const window = Services.wm.getMostRecentWindow("navigator:browser");
const tmp = PathUtils.osTempDir; const tmp = PathUtils.tempDir;
is( is(
await cropAndCompare( await cropAndCompare(
window, window,

View file

@ -28,7 +28,7 @@ ChromeUtils.defineESModuleGetters(lazy, {
}); });
function getHeapSnapshotFileTemplate() { 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)) { if (!isValidSnapshotFileId(snapshotId)) {
return null; 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; readonly attribute DOMString localProfileDir;
/** /**
* The temporary directory for the process. * The OS temporary directory.
*/ */
[Throws, BinaryName="TempDirSync"] [Throws, BinaryName="TempDirSync"]
readonly attribute DOMString tempDir; readonly attribute DOMString tempDir;
/**
* The OS temporary directory.
*/
[Throws, BinaryName="OSTempDirSync"]
readonly attribute DOMString osTempDir;
/** /**
* The libxul path. * The libxul path.
*/ */
@ -157,17 +151,11 @@ partial namespace PathUtils {
Promise<DOMString> getLocalProfileDir(); Promise<DOMString> getLocalProfileDir();
/** /**
* The temporary directory for the process. * The OS temporary directory.
*/ */
[NewObject, BinaryName="GetTempDirAsync"] [NewObject, BinaryName="GetTempDirAsync"]
Promise<DOMString> getTempDir(); Promise<DOMString> getTempDir();
/**
* The OS temporary directory.
*/
[NewObject, BinaryName="GetOSTempDirAsync"]
Promise<DOMString> getOSTempDir();
/** /**
* The libxul path. * The libxul path.
*/ */

View file

@ -440,15 +440,6 @@ void PathUtils::GetTempDirSync(const GlobalObject&, nsString& aResult,
.GetDirectorySync(aResult, aErr, DirectoryCache::Directory::Temp); .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, void PathUtils::GetXulLibraryPathSync(const GlobalObject&, nsString& aResult,
ErrorResult& aErr) { ErrorResult& aErr) {
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
@ -486,15 +477,6 @@ already_AddRefed<Promise> PathUtils::GetTempDirAsync(
.GetDirectoryAsync(aGlobal, aErr, DirectoryCache::Directory::Temp); .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( already_AddRefed<Promise> PathUtils::GetXulLibraryPathAsync(
const GlobalObject& aGlobal, ErrorResult& aErr) { const GlobalObject& aGlobal, ErrorResult& aErr) {
MOZ_ASSERT(!NS_IsMainThread()); MOZ_ASSERT(!NS_IsMainThread());

View file

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

View file

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

View file

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

View file

@ -1517,13 +1517,6 @@ XPCShellDirProvider::GetFile(const char* prop, bool* persistent,
file.forget(result); file.forget(result);
return NS_OK; 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; return NS_ERROR_FAILURE;
} }

View file

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

View file

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

View file

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