mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 793682 - [OS.File] getCurrentDirectory/setCurrentDirectory for the main thread. r=Yoric
This commit is contained in:
parent
0744ad5c35
commit
1b847ad9dc
@ -181,10 +181,10 @@ if (this.Components) {
|
||||
exports.OS.File.stat(Type.path.fromMsg(path)));
|
||||
},
|
||||
getCurrentDirectory: function getCurrentDirectory() {
|
||||
return exports.OS.Shared.Type.path.toMsg(exports.OS.File.curDir);
|
||||
return exports.OS.Shared.Type.path.toMsg(File.getCurrentDirectory());
|
||||
},
|
||||
setCurrentDirectory: function setCurrentDirectory(path) {
|
||||
exports.OS.File.curDir = exports.OS.Shared.Type.path.fromMsg(path);
|
||||
File.setCurrentDirectory(exports.OS.Shared.Type.path.fromMsg(path));
|
||||
},
|
||||
copy: function copy(sourcePath, destPath, options) {
|
||||
return File.copy(Type.path.fromMsg(sourcePath),
|
||||
|
@ -845,20 +845,34 @@
|
||||
File.read = exports.OS.Shared.AbstractFile.read;
|
||||
File.writeAtomic = exports.OS.Shared.AbstractFile.writeAtomic;
|
||||
|
||||
/**
|
||||
* Get the current directory by getCurrentDirectory.
|
||||
*/
|
||||
File.getCurrentDirectory = function getCurrentDirectory() {
|
||||
let path = UnixFile.get_current_dir_name?UnixFile.get_current_dir_name():
|
||||
UnixFile.getwd_auto(null);
|
||||
throw_on_null("getCurrentDirectory",path);
|
||||
return path.readString();
|
||||
};
|
||||
|
||||
/**
|
||||
* Set the current directory by setCurrentDirectory.
|
||||
*/
|
||||
File.setCurrentDirectory = function setCurrentDirectory(path) {
|
||||
throw_on_negative("setCurrentDirectory",
|
||||
UnixFile.chdir(path)
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Get/set the current directory.
|
||||
*/
|
||||
Object.defineProperty(File, "curDir", {
|
||||
set: function(path) {
|
||||
throw_on_negative("curDir",
|
||||
UnixFile.chdir(path)
|
||||
);
|
||||
this.setCurrentDirectory(path);
|
||||
},
|
||||
get: function() {
|
||||
let path = UnixFile.get_current_dir_name?UnixFile.get_current_dir_name():
|
||||
UnixFile.getwd_auto(null);
|
||||
throw_on_null("curDir",path);
|
||||
return path.readString();
|
||||
return this.getCurrentDirectory();
|
||||
}
|
||||
}
|
||||
);
|
||||
|
@ -842,14 +842,9 @@
|
||||
File.writeAtomic = exports.OS.Shared.AbstractFile.writeAtomic;
|
||||
|
||||
/**
|
||||
* Get/set the current directory.
|
||||
* Get the current directory by getCurrentDirectory.
|
||||
*/
|
||||
Object.defineProperty(File, "curDir", {
|
||||
set: function(path) {
|
||||
throw_on_zero("set curDir",
|
||||
WinFile.SetCurrentDirectory(path));
|
||||
},
|
||||
get: function() {
|
||||
File.getCurrentDirectory = function getCurrentDirectory() {
|
||||
// This function is more complicated than one could hope.
|
||||
//
|
||||
// This is due to two facts:
|
||||
@ -862,11 +857,10 @@
|
||||
// the function with a larger buffer, in the (unlikely byt possible)
|
||||
// case in which the process changes directory to a directory with
|
||||
// a longer name between both calls.
|
||||
|
||||
let buffer_size = 4096;
|
||||
while (true) {
|
||||
let array = new (ctypes.ArrayType(ctypes.jschar, buffer_size))();
|
||||
let expected_size = throw_on_zero("get curDir",
|
||||
let expected_size = throw_on_zero("getCurrentDirectory",
|
||||
WinFile.GetCurrentDirectory(buffer_size, array)
|
||||
);
|
||||
if (expected_size <= buffer_size) {
|
||||
@ -880,6 +874,25 @@
|
||||
// converge, as the length of the paths cannot increase infinitely.
|
||||
buffer_size = expected_size;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Set the current directory by setCurrentDirectory.
|
||||
*/
|
||||
File.setCurrentDirectory = function setCurrentDirectory(path) {
|
||||
throw_on_zero("setCurrentDirectory",
|
||||
WinFile.SetCurrentDirectory(path));
|
||||
};
|
||||
|
||||
/**
|
||||
* Get/set the current directory by |curDir|.
|
||||
*/
|
||||
Object.defineProperty(File, "curDir", {
|
||||
set: function(path) {
|
||||
this.setCurrentDirectory(path);
|
||||
},
|
||||
get: function() {
|
||||
return this.getCurrentDirectory();
|
||||
}
|
||||
}
|
||||
);
|
||||
|
@ -441,7 +441,7 @@ function test_iter_dir()
|
||||
let tmp_file = OS.File.open(tmp_file_name, {write: true, trunc:true});
|
||||
tmp_file.close();
|
||||
|
||||
let parent = OS.File.curDir;
|
||||
let parent = OS.File.getCurrentDirectory();
|
||||
ok(true, "test_iter_dir: directory " + parent);
|
||||
let iterator = new OS.File.DirectoryIterator(parent);
|
||||
ok(true, "test_iter_dir: iterator created");
|
||||
@ -671,7 +671,7 @@ function test_info() {
|
||||
"test_info: file 2 has changed between the start of the test and now - " + start + ", " + stop + ", " + change);
|
||||
|
||||
// Test OS.File.stat on directory
|
||||
info = OS.File.stat(OS.File.curDir);
|
||||
info = OS.File.stat(OS.File.getCurrentDirectory());
|
||||
ok(!!info, "test_info: info on directory acquired");
|
||||
ok(info.isDir, "test_info: directory is a directory");
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user