fix a bunch of bugs, including #31079 and #14435. when setting the local path for a server, or the newsrc file for

a news server, make sure the folder or file is unique.
use the hostname as part of the suggestion when creating the directory for the server.

r=bienvenu.
This commit is contained in:
sspitzer%netscape.com 2000-04-01 09:37:24 +00:00
Родитель 194749371e
Коммит 8727cafafb
2 изменённых файлов: 22 добавлений и 23 удалений

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

@ -711,12 +711,8 @@ nsMsgIncomingServer::GetLocalPath(nsIFileSpec **aLocalPath)
if (NS_SUCCEEDED(rv) && *aLocalPath) return rv;
// otherwise, create the path using. note we are using the
// server key instead of the hostname
//
// TODO: handle the case where they migrated a server of hostname "server4"
// and we create a server (with the account wizard) with key "server4"
// we'd get a collision.
// need to modify the code that creates keys to check for disk collision
// hostname, unless that directory exists.
// this should prevent all collisions.
nsXPIDLCString type;
GetType(getter_Copies(type));
@ -732,11 +728,15 @@ nsMsgIncomingServer::GetLocalPath(nsIFileSpec **aLocalPath)
path->CreateDir();
nsXPIDLCString key;
rv = GetKey(getter_Copies(key));
// set the leaf name to "dummy", and then call MakeUnique with a suggested leaf name
rv = path->AppendRelativeUnixPath("dummy");
if (NS_FAILED(rv)) return rv;
rv = path->AppendRelativeUnixPath(key);
nsXPIDLCString hostname;
rv = GetHostName(getter_Copies(hostname));
if (NS_FAILED(rv)) return rv;
rv = path->MakeUniqueWithSuggestedName((const char *)hostname);
if (NS_FAILED(rv)) return rv;
rv = SetLocalPath(path);
if (NS_FAILED(rv)) return rv;

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

@ -36,21 +36,17 @@
#include "nsIRDFService.h"
#include "nsRDFCID.h"
#ifdef DEBUG_seth
#define DO_HASHING_OF_HOSTNAME 1
#endif /* DEBUG_seth */
#ifdef DO_HASHING_OF_HOSTNAME
#include "nsMsgUtils.h"
#endif /* DO_HASHING_OF_HOSTNAME */
#define NEW_NEWS_DIR_NAME "News"
#define PREF_MAIL_NEWSRC_ROOT "mail.newsrc_root"
// this platform specific junk is so the newsrc filenames we create
// will resemble the migrated newsrc filenames.
#if defined(XP_UNIX) || defined(XP_BEOS)
#define NEWSRC_FILE_PREFIX "newsrc-"
#define NEWSRC_FILE_SUFFIX ""
#else
#define NEWSRC_FILE_PREFIX ""
#define NEWSRC_FILE_SUFFIX ".rc"
#endif /* XP_UNIX || XP_BEOS */
static NS_DEFINE_CID(kPrefServiceCID, NS_PREF_CID);
@ -99,14 +95,17 @@ nsNntpIncomingServer::GetNewsrcFilePath(nsIFileSpec **aNewsrcFilePath)
rv = GetHostName(getter_Copies(hostname));
if (NS_FAILED(rv)) return rv;
nsCAutoString newsrcFileName = NEWSRC_FILE_PREFIX;
// set the leaf name to "dummy", and then call MakeUnique with a suggested leaf name
rv = path->AppendRelativeUnixPath("dummy");
if (NS_FAILED(rv)) return rv;
nsCAutoString newsrcFileName = NEWSRC_FILE_PREFIX;
newsrcFileName.Append(hostname);
#ifdef DO_HASHING_OF_HOSTNAME
NS_MsgHashIfNecessary(newsrcFileName);
#endif /* DO_HASHING_OF_HOSTNAME */
path->AppendRelativeUnixPath(newsrcFileName);
newsrcFileName.Append(NEWSRC_FILE_SUFFIX);
rv = path->MakeUniqueWithSuggestedName((const char *)newsrcFileName);
if (NS_FAILED(rv)) return rv;
SetNewsrcFilePath(path);
rv = SetNewsrcFilePath(path);
if (NS_FAILED(rv)) return rv;
*aNewsrcFilePath = path;
NS_ADDREF(*aNewsrcFilePath);