Fix for 45885. Now returning an nsInstallFolder object rather than a string. r=sgehani

git-svn-id: svn://10.0.0.236/trunk@77099 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
dbragg%netscape.com 2000-08-24 19:34:06 +00:00
parent 376142f630
commit 7e2f0598d2
3 changed files with 34 additions and 14 deletions

View File

@ -1606,11 +1606,24 @@ nsInstall::FileOpDirCreate(nsInstallFolder& aTarget, PRInt32* aReturn)
}
PRInt32
nsInstall::FileOpDirGetParent(nsInstallFolder& aTarget, nsIFile** aReturn)
nsInstall::FileOpDirGetParent(nsInstallFolder& aTarget, nsInstallFolder** theParentFolder)
{
nsCOMPtr<nsIFile> parent;
nsCOMPtr<nsIFile> localFile = aTarget.GetFileSpec();
localFile->GetParent(aReturn);
nsresult rv = localFile->GetParent(getter_AddRefs(parent));
if (NS_SUCCEEDED(rv) && parent)
{
nsInstallFolder* folder = new nsInstallFolder();
if (folder == nsnull)
{
return NS_ERROR_OUT_OF_MEMORY;
}
folder->Init(parent);
*theParentFolder = folder;
}
else
theParentFolder = nsnull;
return NS_OK;
}

View File

@ -233,7 +233,7 @@ class nsInstall
PRInt32 Uninstall(const nsString& aPackageName, PRInt32* aReturn);
PRInt32 FileOpDirCreate(nsInstallFolder& aTarget, PRInt32* aReturn);
PRInt32 FileOpDirGetParent(nsInstallFolder& aTarget, nsIFile** aReturn);
PRInt32 FileOpDirGetParent(nsInstallFolder& aTarget, nsInstallFolder** theParentFolder);
PRInt32 FileOpDirRemove(nsInstallFolder& aTarget, PRInt32 aFlags, PRInt32* aReturn);
PRInt32 FileOpDirRename(nsInstallFolder& aSrc, nsString& aTarget, PRInt32* aReturn);
PRInt32 FileOpFileCopy(nsInstallFolder& aSrc, nsInstallFolder& aTarget, PRInt32* aReturn);

View File

@ -64,7 +64,6 @@ extern PRBool ConvertJSValToObj(nsISupports** aSupports,
jsval aValue);
//
// Native method DirCreate
//
@ -119,10 +118,8 @@ JSBool PR_CALLBACK
InstallFileOpDirGetParent(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsInstall* nativeThis = (nsInstall*)JS_GetPrivate(cx, obj);
nsCOMPtr<nsIFile> nativeRet;
nsString nativeRetNSStr;
JSObject *jsObj;
nsInstallFolder *folder;
nsInstallFolder *parentFolder, *folder;
*rval = JSVAL_NULL;
@ -150,18 +147,28 @@ InstallFileOpDirGetParent(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
}
folder = (nsInstallFolder*)JS_GetPrivate(cx, jsObj);
if(!folder || NS_OK != nativeThis->FileOpDirGetParent(*folder, getter_AddRefs(nativeRet)))
if(!folder || NS_OK != nativeThis->FileOpDirGetParent(*folder, &parentFolder))
{
// error, return NULL
return JS_TRUE;
}
char* temp;
nativeRet->GetPath(&temp);
nativeRetNSStr.AssignWithConversion(temp);
if ( parentFolder )
{
/* Now create the new JSObject */
JSObject *fileSpecObject;
JSObject *FileSpecProto = nsnull;
*rval = STRING_TO_JSVAL(JS_NewUCStringCopyN(cx, NS_REINTERPRET_CAST(const jschar*, nativeRetNSStr.GetUnicode()), nativeRetNSStr.Length()));
fileSpecObject = JS_NewObject(cx, &FileSpecObjectClass, FileSpecProto, NULL);
if (fileSpecObject == NULL)
return JS_FALSE;
JS_SetPrivate(cx, fileSpecObject, parentFolder);
if (fileSpecObject == NULL)
return JS_FALSE;
*rval = OBJECT_TO_JSVAL(fileSpecObject);
}
return JS_TRUE;
}