Bugfix for 9604, 8138. r=cathleen, a=chofmann

This commit is contained in:
dveditz%netscape.com 1999-09-27 21:28:03 +00:00
Родитель 603d551cd5
Коммит 85bed52b6f
10 изменённых файлов: 227 добавлений и 78 удалений

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

@ -144,6 +144,7 @@ nsInstall::nsInstall()
mUninstallPackage = PR_FALSE;
mRegisterPackage = PR_FALSE;
mStatusSent = PR_FALSE;
mJarFileLocation = "";
mInstallArguments = "";
@ -236,7 +237,10 @@ void
nsInstall::InternalAbort(PRInt32 errcode)
{
if (mNotifier)
{
mNotifier->FinalStatus(mInstallURL.GetUnicode(), errcode);
mStatusSent = PR_TRUE;
}
nsInstallObject* ie;
if (mInstalledFiles != nsnull)
@ -728,12 +732,15 @@ nsInstall::FinalizeInstall(PRInt32* aReturn)
{
SaveError( *aReturn );
if (mNotifier)
{
mNotifier->FinalStatus(mInstallURL.GetUnicode(), *aReturn);
mStatusSent = PR_TRUE;
}
return NS_OK;
}
if ( mInstalledFiles == NULL || mInstalledFiles->Count() > 0 )
if ( mInstalledFiles != NULL && mInstalledFiles->Count() > 0 )
{
if ( mUninstallPackage )
{
@ -798,17 +805,22 @@ nsInstall::FinalizeInstall(PRInt32* aReturn)
*aReturn = SaveError( REBOOT_NEEDED );
if (mNotifier)
{
mNotifier->FinalStatus(mInstallURL.GetUnicode(), *aReturn);
mStatusSent = PR_TRUE;
}
}
else if ( mInstalledFiles == NULL || mInstalledFiles->Count() == 0 )
else
{
// no actions queued: don't register the package version
// and no need for user confirmation
if (mNotifier)
{
mNotifier->FinalStatus(mInstallURL.GetUnicode(), *aReturn);
}
mStatusSent = PR_TRUE;
}
}
CleanUp();

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

@ -108,10 +108,10 @@ class nsInstall
UNEXPECTED_ERROR = -201,
ACCESS_DENIED = -202,
TOO_MANY_CERTIFICATES = -203,
NO_INSTALLER_CERTIFICATE = -204,
NO_INSTALL_SCRIPT = -204,
NO_CERTIFICATE = -205,
NO_MATCHING_CERTIFICATE = -206,
UNKNOWN_JAR_FILE = -207,
CANT_READ_ARCHIVE = -207,
INVALID_ARGUMENTS = -208,
ILLEGAL_RELATIVE_PATH = -209,
USER_CANCELLED = -210,
@ -132,6 +132,8 @@ class nsInstall
EXTRACTION_FAILED = -225,
FILENAME_ALREADY_USED = -226,
ABORT_INSTALL = -227,
DOWNLOAD_ERROR = -228,
SCRIPT_ERROR = -229,
OUT_OF_MEMORY = -299,
@ -237,6 +239,8 @@ class nsInstall
void GetInstallURL(nsString& url);
void SetInstallURL(const nsString& url);
PRBool GetStatusSent() { return mStatusSent; }
PRInt32 Alert(nsString& string);
PRInt32 Confirm(nsString& string, PRBool* aReturn);
@ -256,6 +260,7 @@ class nsInstall
nsString mPackageFolder;
PRBool mUserCancelled;
PRBool mStatusSent;
PRBool mUninstallPackage;
PRBool mRegisterPackage;

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

@ -281,7 +281,7 @@ PRInt32 nsInstallPatch::Complete()
// FinalizeInstall() leaving things hosed. These piddly errors
// aren't worth that.
VR_Install( tempRegName,
(char*) (const char *) nsNSPRPath(*mTargetFile),
(char*)(const char *)mTargetFile->GetNativePathCString(),
tempVersion,
PR_FALSE );

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

@ -217,18 +217,22 @@ nsInstallTrigger::StartSoftwareUpdate(const nsString& aURL, PRInt32 aFlags, PRBo
trigger->Add( item );
// The Install manager will delete itself when done
rv = mgr->InitManager( trigger );
*aReturn = PR_TRUE;
}
else
{
rv = NS_ERROR_OUT_OF_MEMORY;
delete trigger;
delete mgr;
}
}
else
{
rv = NS_ERROR_OUT_OF_MEMORY;
delete mgr;
}
}
*aReturn = NS_OK; // maybe we should do something more.
return rv;
}
@ -364,6 +368,7 @@ nsInstallTrigger::CompareVersion(const nsString& aRegName, nsIDOMInstallVersion*
VERSION cVersion;
char* tempCString;
REGERR status;
nsInstallVersion regNameVersion;
tempCString = aRegName.ToNewCString();
@ -372,8 +377,6 @@ nsInstallTrigger::CompareVersion(const nsString& aRegName, nsIDOMInstallVersion*
/* if we got the version */
if ( status == REGERR_OK )
{
nsInstallVersion regNameVersion;
if ( VR_ValidateComponent( tempCString ) == REGERR_NOFILE )
{
regNameVersion.Init(0,0,0,0);
@ -385,9 +388,11 @@ nsInstallTrigger::CompareVersion(const nsString& aRegName, nsIDOMInstallVersion*
cVersion.release,
cVersion.build);
}
regNameVersion.CompareTo( aVersion, aReturn );
}
else
regNameVersion.Init(0,0,0,0);
regNameVersion.CompareTo( aVersion, aReturn );
if (tempCString)
Recycle(tempCString);
@ -441,7 +446,7 @@ nsInstallTrigger::CreateTempFileFromURL(const nsString& aURL, nsString& tempFile
{
// Checking to see if the url is local
if ( aURL.EqualsIgnoreCase("file://", 7) )
if ( aURL.EqualsIgnoreCase("file:/", 6) )
{
tempFileString.SetString( nsNSPRPath(nsFileURL(aURL)) );
}

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

@ -48,7 +48,8 @@ enum Install_slots
INSTALL_FORCE = -5,
INSTALL_ARGUMENTS = -6,
INSTALL_URL = -7,
INSTALL_INSTALL = -8
INSTALL_STATUSSENT = -8,
INSTALL_INSTALL = -9
};
/***********************************************************************/
@ -124,6 +125,10 @@ GetInstallProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
break;
}
case INSTALL_STATUSSENT:
*vp = BOOLEAN_TO_JSVAL( a->GetStatusSent() );
break;
case INSTALL_INSTALL:
*vp = OBJECT_TO_JSVAL(obj);
break;
@ -2398,20 +2403,21 @@ static JSPropertySpec InstallProperties[] =
{"jarfile", INSTALL_JARFILE, JSPROP_ENUMERATE | JSPROP_READONLY},
{"arguments", INSTALL_ARGUMENTS, JSPROP_ENUMERATE | JSPROP_READONLY},
{"url", INSTALL_URL, JSPROP_ENUMERATE | JSPROP_READONLY},
{"Install", INSTALL_INSTALL, JSPROP_ENUMERATE | JSPROP_READONLY},
{"_statusSent", INSTALL_STATUSSENT, JSPROP_READONLY},
{"Install", INSTALL_INSTALL, JSPROP_READONLY},
{0}
};
static JSConstDoubleSpec install_constants[] =
{
{ nsInstall::BAD_PACKAGE_NAME, "BAD_PACKAGE_NAME" },
{ nsInstall::UNEXPECTED_ERROR, "UNEXPECTED_ERROR" },
{ nsInstall::BAD_PACKAGE_NAME, "BAD_PACKAGE_NAME" },
{ nsInstall::UNEXPECTED_ERROR, "UNEXPECTED_ERROR" },
{ nsInstall::ACCESS_DENIED, "ACCESS_DENIED" },
{ nsInstall::NO_INSTALLER_CERTIFICATE, "NO_INSTALLER_CERTIFICATE" },
{ nsInstall::NO_INSTALL_SCRIPT, "NO_INSTALL_SCRIPT" },
{ nsInstall::NO_CERTIFICATE, "NO_CERTIFICATE" },
{ nsInstall::NO_MATCHING_CERTIFICATE, "NO_MATCHING_CERTIFICATE" },
{ nsInstall::UNKNOWN_JAR_FILE, "UNKNOWN_JAR_FILE" },
{ nsInstall::CANT_READ_ARCHIVE, "CANT_READ_ARCHIVE" },
{ nsInstall::INVALID_ARGUMENTS, "INVALID_ARGUMENTS" },
{ nsInstall::ILLEGAL_RELATIVE_PATH, "ILLEGAL_RELATIVE_PATH" },
{ nsInstall::USER_CANCELLED, "USER_CANCELLED" },
@ -2432,6 +2438,8 @@ static JSConstDoubleSpec install_constants[] =
{ nsInstall::EXTRACTION_FAILED, "EXTRACTION_FAILED" },
{ nsInstall::FILENAME_ALREADY_USED, "FILENAME_ALREADY_USED" },
{ nsInstall::ABORT_INSTALL, "ABORT_INSTALL" },
{ nsInstall::DOWNLOAD_ERROR, "DOWNLOAD_ERROR" },
{ nsInstall::SCRIPT_ERROR, "SCRIPT_ERROR" },
{ nsInstall::GESTALT_UNKNOWN_ERR, "GESTALT_UNKNOWN_ERR" },
{ nsInstall::GESTALT_INVALID_ARGUMENT, "GESTALT_INVALID_ARGUMENT" },
@ -2497,6 +2505,49 @@ static JSFunctionSpec InstallMethods[] =
{"LogComment", InstallLogComment, 1},
{"Alert", InstallAlert, 1},
{"Confirm", InstallConfirm, 2},
// -- new forms that match prevailing javascript style --
{"abortInstall", InstallAbortInstall, 0},
{"addDirectory", InstallAddDirectory, 6},
{"addFile", InstallAddSubcomponent, 6},
{"alert", InstallAlert, 1},
{"confirm", InstallConfirm, 2},
{"deleteRegisteredFile", InstallDeleteComponent, 1},
{"execute", InstallExecute, 2},
{"finalizeInstall", InstallFinalizeInstall, 0},
{"gestalt", InstallGestalt, 1},
{"getComponentFolder", InstallGetComponentFolder, 2},
{"getFolder", InstallGetFolder, 2},
{"getLastError", InstallGetLastError, 0},
{"getWinProfile", InstallGetWinProfile, 2},
{"getWinRegistry", InstallGetWinRegistry, 0},
{"loadResources", InstallLoadResources, 1},
{"logComment", InstallLogComment, 1},
{"patch", InstallPatch, 5},
{"resetError", InstallResetError, 0},
{"setPackageFolder", InstallSetPackageFolder, 1},
{"startInstall", InstallStartInstall, 4},
{"uninstall", InstallUninstall, 1},
// -- new forms for the file/dir methods --
{"dirCreate", InstallFileOpDirCreate, 1},
{"dirGetParent", InstallFileOpDirGetParent, 1},
{"dirRemove", InstallFileOpDirRemove, 2},
{"dirRename", InstallFileOpDirRename, 2},
{"fileCopy", InstallFileOpFileCopy, 2},
{"fileDelete", InstallFileOpFileDelete, 2},
{"fileExists", InstallFileOpFileExists, 1},
{"fileExecute", InstallFileOpFileExecute, 2},
{"fileGetNativeVersion", InstallFileOpFileGetNativeVersion, 1},
{"fileGetDiskSpaceAvailable", InstallFileOpFileGetDiskSpaceAvailable,1},
{"fileGetModDate", InstallFileOpFileGetModDate, 1},
{"fileGetSize", InstallFileOpFileGetSize, 1},
{"fileIsDirectory", InstallFileOpFileIsDirectory, 1},
{"fileIsFile", InstallFileOpFileIsFile, 1},
{"fileModDateChanged", InstallFileOpFileModDateChanged, 2},
{"fileMove", InstallFileOpFileMove, 2},
{"fileRename", InstallFileOpFileRename, 2},
{"fileWindowsShortcut", InstallFileOpFileWindowsShortcut, 7},
{"fileMacAlias", InstallFileOpFileMacAlias, 2},
{"fileUnixLink", InstallFileOpFileUnixLink, 2},
{0}
};

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

@ -548,6 +548,13 @@ static JSFunctionSpec InstallTriggerGlobalMethods[] =
{"ConditionalSoftwareUpdate", InstallTriggerGlobalConditionalSoftwareUpdate, 5},
{"CompareVersion", InstallTriggerGlobalCompareVersion, 5},
{"GetVersion", InstallTriggerGlobalGetVersion, 2},
// -- new forms to match JS style --
{"updateEnabled", InstallTriggerGlobalUpdateEnabled, 0},
{"install", InstallTriggerGlobalInstall, 2},
{"startSoftwareUpdate", InstallTriggerGlobalStartSoftwareUpdate, 2},
{"conditionalSoftwareUpdate", InstallTriggerGlobalConditionalSoftwareUpdate, 5},
{"compareVersion", InstallTriggerGlobalCompareVersion, 5},
{"getVersion", InstallTriggerGlobalGetVersion, 2},
{0}
};

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

@ -352,7 +352,8 @@ nsSoftwareUpdate::RunNextInstall()
mInstalling = PR_TRUE;
else
{
NS_ERROR("leaking all nsInstallInfos left in queue");
// bogus elements got into the queue
NS_ERROR("leaks remaining nsInstallInfos, please file bug!");
rv = NS_ERROR_NULL_POINTER;
VR_Close();
}
@ -386,7 +387,7 @@ nsSoftwareUpdate::SetProgramDirectory(nsIFileSpec *aDir)
// fix GetFolder return path
mProgramDir = aDir;
mProgramDir->AddRef();
NS_ADDREF(mProgramDir);
// setup version registry path
char* path;

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

@ -141,15 +141,11 @@ GetInstallScriptFromJarfile(const char* jarFile, char** scriptBuffer, PRUint32 *
// Open the jarfile
if (hZip)
rv = hZip->Open( jarFile, &result );
if (NS_FAILED(rv))
if ( NS_FAILED(rv) || result != 0 )
{
NS_IF_RELEASE(hZip);
return rv;
}
if (result != 0)
{
NS_IF_RELEASE(hZip);
return NS_ERROR_FAILURE;
return nsInstall::CANT_READ_ARCHIVE;
}
@ -163,15 +159,10 @@ GetInstallScriptFromJarfile(const char* jarFile, char** scriptBuffer, PRUint32 *
// Extract the install.js file.
rv = hZip->Extract( "install.js", nsNSPRPath(installJSFileSpec), &result );
if (NS_FAILED(rv))
if ( NS_FAILED(rv) || result != 0 )
{
NS_IF_RELEASE( hZip );
return rv;
}
if (result != 0)
{
NS_IF_RELEASE(hZip);
return NS_ERROR_FAILURE;
return nsInstall::NO_INSTALL_SCRIPT;
}
// Read it into a buffer
@ -184,7 +175,7 @@ GetInstallScriptFromJarfile(const char* jarFile, char** scriptBuffer, PRUint32 *
buffer = new char[bufferLength + 1];
if (buffer == nsnull)
return NS_ERROR_FAILURE;
return nsInstall::CANT_READ_ARCHIVE;
rv = (fileStream.GetIStream())->Read(buffer, bufferLength, &readLength);
@ -195,6 +186,7 @@ GetInstallScriptFromJarfile(const char* jarFile, char** scriptBuffer, PRUint32 *
}
else
{
rv = nsInstall::CANT_READ_ARCHIVE;
delete [] buffer;
}
@ -311,6 +303,9 @@ extern "C" void RunInstallOnThread(void *data)
JSContext *cx;
JSObject *glob;
PRInt32 finalStatus;
PRBool sendStatus = PR_FALSE;
nsIXPINotifier *notifier;
nsresult rv;
@ -334,49 +329,88 @@ extern "C" void RunInstallOnThread(void *data)
nsString args;
installInfo->GetArguments(args);
char *jarpath;
char *jarpath; // XXX this should be an nsIFileSpec or moral equivalent
installInfo->GetLocalFile(&jarpath);
if (jarpath)
{
rv = GetInstallScriptFromJarfile( jarpath,
&scriptBuffer,
&scriptLength);
if (!jarpath)
goto bail;
if ( rv == NS_OK && scriptBuffer )
{
rv = SetupInstallContext( jarpath,
url.GetUnicode(),
args.GetUnicode(),
&rt, &cx, &glob);
rv = GetInstallScriptFromJarfile( jarpath,
&scriptBuffer,
&scriptLength);
if (NS_SUCCEEDED(rv))
{
// Go ahead and run!!
jsval rval;
// XXX memory leaks!
if (NS_FAILED(rv) || scriptBuffer == nsnull)
goto bail;
PRBool ok = JS_EvaluateScript( cx,
glob,
scriptBuffer,
scriptLength,
nsnull,
0,
&rval);
rv = SetupInstallContext( jarpath,
url.GetUnicode(),
args.GetUnicode(),
&rt, &cx, &glob);
if (NS_FAILED(rv))
goto bail; // TODO need to log that this failed!
if (!ok)
{
// problem compiling or running script
sendStatus = PR_TRUE;
finalStatus = nsInstall::SCRIPT_ERROR;
}
else
{
// check to make sure the script sent back a status
jsval sent;
if ( !JS_GetProperty( cx, glob, "_statusSent", &sent ) ||
! JSVAL_TO_BOOLEAN(sent) )
{
sendStatus = PR_TRUE;
finalStatus = nsInstall::SCRIPT_ERROR;
}
}
// Go ahead and run!!
jsval rval;
JS_DestroyContext(cx);
JS_DestroyRuntime(rt);
}
else
{
// couldn't initialize install context
sendStatus = PR_TRUE;
finalStatus = nsInstall::UNEXPECTED_ERROR;
}
}
else
{
// could not extract script
sendStatus = PR_TRUE;
finalStatus = (rv != NS_OK) ? rv : nsInstall::NO_INSTALL_SCRIPT;
}
}
else
{
// no path to local jar archive
sendStatus = PR_TRUE;
finalStatus = nsInstall::DOWNLOAD_ERROR;
}
JS_EvaluateScript(cx,
glob,
scriptBuffer,
scriptLength,
nsnull,
0,
&rval);
JS_DestroyContext(cx);
JS_DestroyRuntime(rt);
bail:
if(notifier)
{
if ( sendStatus )
notifier->FinalStatus( url.GetUnicode(), finalStatus );
notifier->AfterJavascriptEvaluation( url.GetUnicode() );
}
if (scriptBuffer) delete [] scriptBuffer;
if (jarpath)
{
if ( !url.Equals("file://",7) )
if ( !url.Equals("file:/",PR_FALSE,6) )
{
// delete the jarfile only if we've downloaded it
PR_Delete(jarpath);

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

@ -60,11 +60,7 @@ class nsXPITriggerItem
nsCOMPtr<nsIFileSpec> mFile;
PRBool IsFileURL() {
nsString startsWith;
mURL.Left(startsWith,7);
return startsWith.Equals("file://");
}
PRBool IsFileURL() { return mURL.Equals("file:/",PR_FALSE,6); }
private:
//-- prevent inadvertent copies and assignments

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

@ -132,7 +132,11 @@ nsXPInstallManager::InitManager(nsXPITriggerInfo* aTriggers)
mTriggers = aTriggers;
if ( !mTriggers || mTriggers->Size() == 0 )
{
rv = NS_ERROR_INVALID_POINTER;
NS_RELEASE_THIS();
return rv;
}
//-----------------------------------------------------
// confirm that install is OK... use stock Confirm()
@ -174,7 +178,8 @@ nsXPInstallManager::InitManager(nsXPITriggerInfo* aTriggers)
if ( dlg )
{
rv = dlg->QueryInterface( nsIXPIProgressDlg::GetIID(), getter_AddRefs(mDlg) );
rv = dlg->QueryInterface( nsIXPIProgressDlg::GetIID(),
getter_AddRefs(mDlg) );
if (NS_SUCCEEDED(rv))
{
rv = mDlg->Open();
@ -184,9 +189,24 @@ nsXPInstallManager::InitManager(nsXPITriggerInfo* aTriggers)
rv = NS_ERROR_OUT_OF_MEMORY;
}
// --- clean up on error
if (!NS_SUCCEEDED(rv))
PRInt32 cbstatus = 0; // callback status
if (NS_SUCCEEDED(rv) && !OKtoInstall )
cbstatus = nsInstall::USER_CANCELLED;
else if (!NS_SUCCEEDED(rv))
cbstatus = nsInstall::UNEXPECTED_ERROR;
if ( cbstatus != 0 )
{
// --- inform callbacks of error
for (PRUint32 i = 0; i < mTriggers->Size(); i++)
{
mTriggers->SendStatus( mTriggers->Get(i)->mURL.GetUnicode(),
cbstatus );
}
// -- must delete ourselves if not continuing
NS_RELEASE_THIS();
}
return rv;
}
@ -215,7 +235,9 @@ nsresult nsXPInstallManager::DownloadNext()
getter_AddRefs(mItem->mFile) );
if (NS_FAILED(rv))
{
// XXX serious problem with trigger! try to carry on
// serious problem with trigger! try to carry on
mTriggers->SendStatus( mItem->mURL.GetUnicode(),
nsInstall::DOWNLOAD_ERROR );
mItem->mFile = 0;
}
@ -256,7 +278,9 @@ nsresult nsXPInstallManager::DownloadNext()
if (NS_FAILED(rv))
{
// XXX announce failure somehow
// announce failure
mTriggers->SendStatus( mItem->mURL.GetUnicode(),
nsInstall::DOWNLOAD_ERROR );
mItem->mFile = 0;
// carry on with the next one
rv = DownloadNext();
@ -282,9 +306,10 @@ nsresult nsXPInstallManager::DownloadNext()
this );
if (NS_SUCCEEDED(rv))
PR_AtomicIncrement(&mNumJars);
else
mTriggers->SendStatus( mItem->mURL.GetUnicode(),
nsInstall::UNEXPECTED_ERROR );
}
else
; // XXX announce failure
}
}
else
@ -351,6 +376,19 @@ nsXPInstallManager::OnStopRequest(nsIChannel* channel, nsISupports *ctxt,
}
mItem->mFile->CloseStream();
if (!NS_SUCCEEDED(rv))
{
nsFileSpec fspec;
rv = mItem->mFile->GetFileSpec(&fspec);
if ( NS_SUCCEEDED(rv) && fspec.Exists() )
fspec.Delete(0);
mItem->mFile = 0;
mTriggers->SendStatus( mItem->mURL.GetUnicode(),
nsInstall::DOWNLOAD_ERROR );
}
DownloadNext();
return rv;
}