fix for bug #364599: some newly created profile files are write protected.

For Firefox 2.0.0.1-de, the default bookmarks.html, localstore.rdf, and mimeTypes.rdf (as well as search.rdf, but that is unused) files had the wrong permissions, which caused several problems.

Going forward, bsmedberg has made it so the build system will fix this problem if it happens again.  But for those 2.0.0.1-de users who were affected, this change will fix the permissions on these files.

r=bsmedberg
This commit is contained in:
sspitzer%mozilla.org 2007-01-10 21:48:07 +00:00
Родитель 0bfebb87b7
Коммит 67de309fbc
2 изменённых файлов: 34 добавлений и 2 удалений

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

@ -114,8 +114,10 @@ nsBrowserDirectoryProvider::GetFile(const char *aKey, PRBool *aPersist,
char const* leafName = nsnull;
PRBool restoreBookmarksBackup = PR_FALSE;
PRBool ensureFilePermissions = PR_FALSE;
if (!strcmp(aKey, NS_APP_BOOKMARKS_50_FILE)) {
ensureFilePermissions = PR_TRUE;
restoreBookmarksBackup = PR_TRUE;
leafName = "bookmarks.html";
@ -195,6 +197,19 @@ nsBrowserDirectoryProvider::GetFile(const char *aKey, PRBool *aPersist,
EnsureProfileFile(leafstr, parentDir, file);
}
if (ensureFilePermissions) {
PRBool fileToEnsureExists;
PRBool isWritable;
if (NS_SUCCEEDED(file->Exists(&fileToEnsureExists)) && fileToEnsureExists
&& NS_SUCCEEDED(file->IsWritable(&isWritable)) && !isWritable) {
PRUint32 permissions;
if (NS_SUCCEEDED(file->GetPermissions(&permissions))) {
rv = file->SetPermissions(permissions | 0644);
NS_ASSERTION(NS_SUCCEEDED(rv), "failed to ensure file permissions");
}
}
}
*aPersist = PR_TRUE;
NS_ADDREF(*aResult = file);

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

@ -314,6 +314,8 @@ nsXREDirProvider::GetFile(const char* aProperty, PRBool* aPersistent,
return NS_OK;
}
PRBool ensureFilePermissions = PR_FALSE;
if (NS_SUCCEEDED(GetProfileDir(getter_AddRefs(file)))) {
if (!strcmp(aProperty, NS_APP_PREFS_50_DIR)) {
rv = NS_OK;
@ -332,6 +334,7 @@ nsXREDirProvider::GetFile(const char* aProperty, PRBool* aPersistent,
else {
rv = file->AppendNative(NS_LITERAL_CSTRING("localstore.rdf"));
EnsureProfileFileExists(file);
ensureFilePermissions = PR_TRUE;
}
}
else if (!strcmp(aProperty, NS_APP_HISTORY_50_FILE)) {
@ -340,6 +343,7 @@ nsXREDirProvider::GetFile(const char* aProperty, PRBool* aPersistent,
else if (!strcmp(aProperty, NS_APP_USER_MIMETYPES_50_FILE)) {
rv = file->AppendNative(NS_LITERAL_CSTRING("mimeTypes.rdf"));
EnsureProfileFileExists(file);
ensureFilePermissions = PR_TRUE;
}
else if (!strcmp(aProperty, NS_APP_STORAGE_50_FILE)) {
rv = file->AppendNative(NS_LITERAL_CSTRING("storage.sdb"));
@ -364,6 +368,19 @@ nsXREDirProvider::GetFile(const char* aProperty, PRBool* aPersistent,
if (NS_FAILED(rv) || !file)
return NS_ERROR_FAILURE;
if (ensureFilePermissions) {
PRBool fileToEnsureExists;
PRBool isWritable;
if (NS_SUCCEEDED(file->Exists(&fileToEnsureExists)) && fileToEnsureExists
&& NS_SUCCEEDED(file->IsWritable(&isWritable)) && !isWritable) {
PRUint32 permissions;
if (NS_SUCCEEDED(file->GetPermissions(&permissions))) {
rv = file->SetPermissions(permissions | 0644);
NS_ASSERTION(NS_SUCCEEDED(rv), "failed to ensure file permissions");
}
}
}
NS_ADDREF(*aFile = file);
return NS_OK;
}