mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-01 11:27:55 +00:00
Bug 557539: Trying to set nsILocalFile.lastModifiedTime for a directory on windows throws NS_ERROR_ACCESS_DENIED. r=jimm
This commit is contained in:
parent
c01d99b879
commit
1ba52b15f5
@ -1963,12 +1963,14 @@ nsLocalFile::SetLastModifiedTimeOfLink(PRInt64 aLastModifiedTime)
|
||||
nsresult
|
||||
nsLocalFile::SetModDate(PRInt64 aLastModifiedTime, const PRUnichar *filePath)
|
||||
{
|
||||
// The FILE_FLAG_BACKUP_SEMANTICS is required in order to change the
|
||||
// modification time for directories.
|
||||
HANDLE file = ::CreateFileW(filePath, // pointer to name of the file
|
||||
GENERIC_WRITE, // access (write) mode
|
||||
0, // share mode
|
||||
NULL, // pointer to security attributes
|
||||
OPEN_EXISTING, // how to create
|
||||
0, // file attributes
|
||||
FILE_FLAG_BACKUP_SEMANTICS, // file attributes
|
||||
NULL);
|
||||
|
||||
if (file == INVALID_HANDLE_VALUE)
|
||||
|
@ -38,6 +38,10 @@
|
||||
|
||||
const Cr = Components.results;
|
||||
const CC = Components.Constructor;
|
||||
const Ci = Components.interfaces;
|
||||
|
||||
const MAX_TIME_DIFFERENCE = 2500;
|
||||
const MILLIS_PER_DAY = 1000 * 60 * 60 * 24;
|
||||
|
||||
var LocalFile = CC("@mozilla.org/file/local;1", "nsILocalFile", "initWithPath");
|
||||
|
||||
@ -45,6 +49,8 @@ function run_test()
|
||||
{
|
||||
test_toplevel_parent_is_null();
|
||||
test_normalize_crash_if_media_missing();
|
||||
test_file_modification_time();
|
||||
test_directory_modification_time();
|
||||
}
|
||||
|
||||
function test_toplevel_parent_is_null()
|
||||
@ -82,3 +88,71 @@ function test_normalize_crash_if_media_missing()
|
||||
}
|
||||
}
|
||||
|
||||
// Tests that changing a file's modification time is possible
|
||||
function test_file_modification_time()
|
||||
{
|
||||
var file = do_get_profile();
|
||||
file.append("testfile");
|
||||
|
||||
// Should never happen but get rid of it anyway
|
||||
if (file.exists())
|
||||
file.remove(true);
|
||||
|
||||
var now = Date.now();
|
||||
file.create(Ci.nsIFile.NORMAL_FILE_TYPE, 0644);
|
||||
do_check_true(file.exists());
|
||||
|
||||
// Modification time may be out by up to 2 seconds on FAT filesystems. Test
|
||||
// with a bit of leeway, close enough probably means it is correct.
|
||||
var diff = Math.abs(file.lastModifiedTime - now);
|
||||
do_check_true(diff < MAX_TIME_DIFFERENCE);
|
||||
|
||||
var yesterday = now - MILLIS_PER_DAY;
|
||||
file.lastModifiedTime = yesterday;
|
||||
|
||||
diff = Math.abs(file.lastModifiedTime - yesterday);
|
||||
do_check_true(diff < MAX_TIME_DIFFERENCE);
|
||||
|
||||
var tomorrow = now - MILLIS_PER_DAY;
|
||||
file.lastModifiedTime = tomorrow;
|
||||
|
||||
diff = Math.abs(file.lastModifiedTime - tomorrow);
|
||||
do_check_true(diff < MAX_TIME_DIFFERENCE);
|
||||
|
||||
file.remove(true);
|
||||
}
|
||||
|
||||
// Tests that changing a directory's modification time is possible
|
||||
function test_directory_modification_time()
|
||||
{
|
||||
var dir = do_get_profile();
|
||||
dir.append("testdir");
|
||||
|
||||
// Should never happen but get rid of it anyway
|
||||
if (dir.exists())
|
||||
dir.remove(true);
|
||||
|
||||
var now = Date.now();
|
||||
dir.create(Ci.nsIFile.DIRECTORY_TYPE, 0755);
|
||||
do_check_true(dir.exists());
|
||||
|
||||
// Modification time may be out by up to 2 seconds on FAT filesystems. Test
|
||||
// with a bit of leeway, close enough probably means it is correct.
|
||||
var diff = Math.abs(dir.lastModifiedTime - now);
|
||||
do_check_true(diff < MAX_TIME_DIFFERENCE);
|
||||
|
||||
var yesterday = now - MILLIS_PER_DAY;
|
||||
dir.lastModifiedTime = yesterday;
|
||||
|
||||
diff = Math.abs(dir.lastModifiedTime - yesterday);
|
||||
do_check_true(diff < MAX_TIME_DIFFERENCE);
|
||||
|
||||
var tomorrow = now - MILLIS_PER_DAY;
|
||||
dir.lastModifiedTime = tomorrow;
|
||||
|
||||
diff = Math.abs(dir.lastModifiedTime - tomorrow);
|
||||
do_check_true(diff < MAX_TIME_DIFFERENCE);
|
||||
|
||||
dir.remove(true);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user