зеркало из https://github.com/mozilla/pjs.git
fix for #22099, newsrc migration problems on linux. r=mscott, a=syd.
This commit is contained in:
Родитель
6444a09bb5
Коммит
31a1365018
|
@ -2468,40 +2468,22 @@ nsMsgAccountManager::MigrateNewsAccounts(nsIMsgIdentity *identity)
|
|||
|
||||
inputStream.close();
|
||||
#else /* USE_NEWSRC_MAP_FILE */
|
||||
rv = m_prefs->GetFilePref(PREF_PREMIGRATION_NEWS_DIRECTORY, getter_AddRefs(newsDir));
|
||||
if (NS_FAILED(rv)) {
|
||||
#ifdef DEBUG_ACCOUNTMANAGER
|
||||
printf("%s was not set, attempting to use %s instead.\n",PREF_PREMIGRATION_NEWS_DIRECTORY,PREF_NEWS_DIRECTORY);
|
||||
#endif
|
||||
rv = m_prefs->GetFilePref(PREF_NEWS_DIRECTORY, getter_AddRefs(newsDir));
|
||||
}
|
||||
rv = m_prefs->GetFilePref(PREF_NEWS_DIRECTORY, getter_AddRefs(newsDir));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
rv = newsDir->GetFileSpec(&newsrcDir);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
else {
|
||||
// "news.directory" and "premigration.news.directory" fail, use the home directory.
|
||||
#ifdef XP_UNIX
|
||||
nsSpecialSystemDirectory homeDir(nsSpecialSystemDirectory::Unix_HomeDirectory);
|
||||
#elif XP_BEOS
|
||||
nsSpecialSystemDirectory homeDir(nsSpecialSystemDirectory::BeOS_HomeDirectory);
|
||||
#else
|
||||
#error where_are_your_newsrc_files
|
||||
#endif /* XP_UNIX, XP_BEOS */
|
||||
newsrcDir = homeDir;
|
||||
}
|
||||
rv = newsDir->GetFileSpec(&newsrcDir);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
for (nsDirectoryIterator i(newsrcDir, PR_FALSE); i.Exists(); i++) {
|
||||
nsFileSpec possibleRcFile = i.Spec();
|
||||
|
||||
char *filename = possibleRcFile.GetLeafName();
|
||||
|
||||
if ((PL_strncmp(NEWSRC_FILE_PREFIX, filename, PL_strlen(NEWSRC_FILE_PREFIX)) == 0) && (PL_strlen(filename) > PL_strlen(NEWSRC_FILE_PREFIX))) {
|
||||
if ((PL_strncmp(NEWSRC_FILE_PREFIX_5x, filename, PL_strlen(NEWSRC_FILE_PREFIX_5x)) == 0) && (PL_strlen(filename) > PL_strlen(NEWSRC_FILE_PREFIX_5x))) {
|
||||
#ifdef DEBUG_ACCOUNTMANAGER
|
||||
printf("found a newsrc file: %s\n", filename);
|
||||
#endif
|
||||
char *hostname = filename + PL_strlen(NEWSRC_FILE_PREFIX);
|
||||
char *hostname = filename + PL_strlen(NEWSRC_FILE_PREFIX_5x);
|
||||
rv = MigrateNewsAccount(identity, hostname, possibleRcFile, newsHostsDir);
|
||||
if (NS_FAILED(rv)) {
|
||||
// failed to migrate. bail out
|
||||
|
|
|
@ -35,8 +35,10 @@
|
|||
* file name length limitations.
|
||||
*/
|
||||
#if defined(XP_UNIX) || defined(XP_BEOS)
|
||||
// if you don't use the fat file, then you need to specify the newsrc file prefix you use
|
||||
#define NEWSRC_FILE_PREFIX ".newsrc-"
|
||||
/* in 4.x, the prefix was ".newsrc-", in 5.0, the profile migrator code copies the newsrc files from
|
||||
* ~/.newsrc-* to ~/.mozilla/<profile>/News/newsrc-*
|
||||
*/
|
||||
#define NEWSRC_FILE_PREFIX_5x "newsrc-"
|
||||
#else
|
||||
#define USE_NEWSRC_MAP_FILE
|
||||
|
||||
|
|
|
@ -59,6 +59,8 @@
|
|||
|
||||
#define PREF_FILE_HEADER_STRING "# Mozilla User Preferences "
|
||||
|
||||
#define MAX_PREF_LEN 1024
|
||||
|
||||
#if defined(XP_UNIX)
|
||||
#define IMAP_MAIL_FILTER_FILE_NAME_IN_4x "mailrule"
|
||||
#define POP_MAIL_FILTER_FILE_NAME_IN_4x "mailrule"
|
||||
|
@ -66,6 +68,7 @@
|
|||
#define COOKIES_FILE_NAME_IN_4x "cookies"
|
||||
#define BOOKMARKS_FILE_NAME_IN_4x "bookmarks.html"
|
||||
#define HISTORY_FILE_NAME_IN_4x "history.dat"
|
||||
#define NEWSRC_PREFIX_IN_4x ".newsrc-"
|
||||
#elif defined(XP_MAC)
|
||||
#define IMAP_MAIL_FILTER_FILE_NAME_IN_4x "<hostname> Rules"
|
||||
#define POP_MAIL_FILTER_FILE_NAME_IN_4x "Filter Rules"
|
||||
|
@ -95,7 +98,7 @@
|
|||
#define HAVE_MOVEMAIL 1
|
||||
#endif /* XP_UNIX */
|
||||
|
||||
#define PREMIGRATION_PREFIX "premigration"
|
||||
#define PREMIGRATION_PREFIX "premigration."
|
||||
#define PREF_MAIL_DIRECTORY "mail.directory"
|
||||
#define PREF_NEWS_DIRECTORY "news.directory"
|
||||
#define PREF_MAIL_IMAP_ROOT_DIR "mail.imap.root_dir"
|
||||
|
@ -342,7 +345,8 @@ extern "C" void ProfileMigrationController(void *data)
|
|||
migratorInterface,
|
||||
PROXY_SYNC,
|
||||
getter_AddRefs(prefProxy));
|
||||
|
||||
if (NS_FAILED(rv)) return;
|
||||
|
||||
prefProxy->WindowCloseCallback();
|
||||
}
|
||||
|
||||
|
@ -909,11 +913,16 @@ nsPrefMigration::ProcessPrefsCallback(const char* oldProfilePathStr, const char
|
|||
if (NS_FAILED(rv)) return rv;
|
||||
rv = DoTheCopy(oldNewsPath, newNewsPath, PR_TRUE);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
#ifdef DEBUG_seth
|
||||
#ifdef XP_UNIX
|
||||
printf("TODO: do we need to copy/move/rename the .newsrc files?\n");
|
||||
#endif /* XP_UNIX */
|
||||
#endif
|
||||
|
||||
#ifdef NEED_TO_COPY_AND_RENAME_NEWSRC_FILES
|
||||
/* in 4.x, the newsrc files were in $HOME. Now that we can have multiple
|
||||
* profiles in 5.x, with the same user, this won't fly.
|
||||
* when they migrate, we need to copy from $HOME/.newsrc-<host> to
|
||||
* ~/.mozilla/<profile>/News/newsrc-<host>
|
||||
*/
|
||||
rv = CopyAndRenameNewsrcFiles(newNewsPath);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
#endif /* NEED_TO_COPY_AND_RENAME_NEWSRC_FILES */
|
||||
if(serverType == IMAP_4X_MAIL_TYPE) {
|
||||
rv = DoTheCopyAndRename(oldIMAPMailPath, newIMAPMailPath, PR_TRUE, needToRenameFilterFiles, IMAP_MAIL_FILTER_FILE_NAME_IN_4x, IMAP_MAIL_FILTER_FILE_NAME_IN_5x);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
@ -1137,7 +1146,24 @@ nsStringEndsWith(nsString& name, const char *ending)
|
|||
else {
|
||||
return PR_FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static PRBool
|
||||
nsStringStartsWith(nsString& name, const char *starting)
|
||||
{
|
||||
if (!starting) return PR_FALSE;
|
||||
PRInt32 len = name.Length();
|
||||
if (len == 0) return PR_FALSE;
|
||||
|
||||
PRInt32 startingLen = PL_strlen(starting);
|
||||
if (len > startingLen && name.RFind(starting, PR_TRUE) == 0) {
|
||||
return PR_TRUE;
|
||||
}
|
||||
else {
|
||||
return PR_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------------
|
||||
* GetSizes reads the 4.x files in the profile tree and accumulates their sizes
|
||||
*
|
||||
|
@ -1268,6 +1294,47 @@ nsPrefMigration::CheckForSpace(nsFileSpec newProfilePath, PRFloat64 requiredSpac
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
#ifdef NEED_TO_COPY_AND_RENAME_NEWSRC_FILES
|
||||
nsresult
|
||||
nsPrefMigration::CopyAndRenameNewsrcFiles(nsIFileSpec * newPathSpec)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr <nsIFileSpec>oldPathSpec;
|
||||
nsFileSpec oldPath;
|
||||
nsFileSpec newPath;
|
||||
char* folderName = nsnull;
|
||||
nsAutoString fileOrDirNameStr;
|
||||
|
||||
rv = GetPremigratedFilePref(PREF_NEWS_DIRECTORY, getter_AddRefs(oldPathSpec));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = oldPathSpec->GetFileSpec(&oldPath);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = newPathSpec->GetFileSpec(&newPath);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
for (nsDirectoryIterator dir(oldPath, PR_FALSE); dir.Exists(); dir++)
|
||||
{
|
||||
nsFileSpec fileOrDirName = (nsFileSpec&)dir; //set first file or dir to a nsFileSpec
|
||||
folderName = fileOrDirName.GetLeafName(); //get the filename without the full path
|
||||
fileOrDirNameStr = folderName;
|
||||
|
||||
if (nsStringStartsWith(fileOrDirNameStr, NEWSRC_PREFIX_IN_4x)) {
|
||||
#ifdef DEBUG_seth
|
||||
printf("rc file == %s\n",folderName);
|
||||
#endif /* DEBUG_seth */
|
||||
|
||||
fileOrDirName.CopyToDir(newPath);
|
||||
|
||||
nsFileSpec newFile = newPath;
|
||||
newFile += fileOrDirNameStr;
|
||||
newFile.Rename(folderName + 1); /* rename .newsrc-news to newsrc-news, no need to keep it hidden anymore */
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
#endif /* NEED_TO_COPY_AND_RENAME_NEWSRC_FILES */
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* DoTheCopyAndRename copies the files listed in oldPath to newPath
|
||||
* and renames files, if necessary
|
||||
|
@ -1689,23 +1756,40 @@ nsPrefMigration::Rename4xFileAfterMigration(nsIFileSpec * profilePath, const cha
|
|||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsPrefMigration::GetPremigratedFilePref(const char *pref_name, nsIFileSpec **path)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
if (!pref_name) return NS_ERROR_FAILURE;
|
||||
|
||||
char premigration_pref[MAX_PREF_LEN];
|
||||
PR_snprintf(premigration_pref,MAX_PREF_LEN,"%s%s",PREMIGRATION_PREFIX,pref_name);
|
||||
#ifdef DEBUG_seth
|
||||
printf("getting %s (into a nsFileSpec)\n", premigration_pref);
|
||||
#endif
|
||||
rv = m_prefs->GetFilePref((const char *)premigration_pref, path);
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsPrefMigration::SetPremigratedFilePref(const char *pref_name, nsIFileSpec *path)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
if (!pref_name) return NS_ERROR_FAILURE;
|
||||
|
||||
// save off the old pref, prefixed with "premigration"
|
||||
// for example, we need the old "mail.directory" pref when
|
||||
// migrating the copies and folder prefs in nsMsgAccountManager.cpp
|
||||
//
|
||||
// note we do this for all platforms.
|
||||
char *premigration_pref = nsnull;
|
||||
premigration_pref = PR_smprintf("%s.%s", PREMIGRATION_PREFIX,pref_name);
|
||||
if (!premigration_pref) return NS_ERROR_FAILURE;
|
||||
char premigration_pref[MAX_PREF_LEN];
|
||||
PR_snprintf(premigration_pref,MAX_PREF_LEN,"%s%s",PREMIGRATION_PREFIX,pref_name);
|
||||
#ifdef DEBUG_seth
|
||||
printf("setting %s (from a nsFileSpec) for later...\n", premigration_pref);
|
||||
#endif
|
||||
rv = m_prefs->SetFilePref(premigration_pref, path, PR_FALSE /* set default */);
|
||||
PR_FREEIF(premigration_pref);
|
||||
rv = m_prefs->SetFilePref((const char *)premigration_pref, path, PR_FALSE /* set default */);
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
|
|
@ -43,6 +43,10 @@
|
|||
#define IMAP_MAIL_FILTER_FILE_NAME_FORMAT_IN_4x "%s Rules"
|
||||
#endif
|
||||
|
||||
#ifdef XP_UNIX
|
||||
#define NEED_TO_COPY_AND_RENAME_NEWSRC_FILES
|
||||
#endif
|
||||
|
||||
class nsPrefMigration: public nsIPrefMigration
|
||||
{
|
||||
public:
|
||||
|
@ -100,6 +104,10 @@ class nsPrefMigration: public nsIPrefMigration
|
|||
const char *oldName,
|
||||
const char *newName);
|
||||
|
||||
#ifdef NEED_TO_COPY_AND_RENAME_NEWSRC_FILES
|
||||
nsresult CopyAndRenameNewsrcFiles(nsIFileSpec *newPath);
|
||||
#endif /* NEED_TO_COPY_AND_RENAME_NEWSRC_FILES */
|
||||
|
||||
nsresult DoSpecialUpdates(nsIFileSpec * profilePath);
|
||||
nsresult Rename4xFileAfterMigration(nsIFileSpec *profilePath, const char *oldFileName, const char *newFileName);
|
||||
#ifdef IMAP_MAIL_FILTER_FILE_NAME_FORMAT_IN_4x
|
||||
|
@ -109,6 +117,9 @@ class nsPrefMigration: public nsIPrefMigration
|
|||
nsresult RenameAndMove4xPopFilterFile(nsIFileSpec *profilePath);
|
||||
|
||||
nsresult SetPremigratedFilePref(const char *pref_name, nsIFileSpec *filePath);
|
||||
#ifdef NEED_TO_COPY_AND_RENAME_NEWSRC_FILES
|
||||
nsresult GetPremigratedFilePref(const char *pref_name, nsIFileSpec **filePath);
|
||||
#endif /* NEED_TO_COPY_AND_RENAME_NEWSRC_FILES */
|
||||
|
||||
|
||||
nsIPref* m_prefs;
|
||||
|
|
Загрузка…
Ссылка в новой задаче