зеркало из https://github.com/mozilla/gecko-dev.git
change nsIFile::Spawn to take an array of arguments instead of just a single flat string. bug #27843. r=dougt, a=chofmann. also, implement nsIFile::Normalize for unix. bug #17948. r=shaver, a=chofmann
This commit is contained in:
Родитель
29a6c841a0
Коммит
33ad4046c8
|
@ -20,6 +20,7 @@
|
|||
*
|
||||
* Contributor(s):
|
||||
* Doug Turner <dougt@netscape.com>
|
||||
* Christopher Blizzard <blizzard@mozilla.org>
|
||||
*/
|
||||
|
||||
|
||||
|
@ -150,7 +151,7 @@ interface nsIFile : nsISupports
|
|||
* execution. 'args' will be passed through on the command line
|
||||
* if the OS supports that.
|
||||
*/
|
||||
void spawn([const] in string args);
|
||||
void spawn([array, size_is(count)] in string args, in unsigned long count);
|
||||
|
||||
/**
|
||||
* This will try to delete this file. The 'recursive' flag
|
||||
|
|
|
@ -1026,7 +1026,7 @@ nsLocalFile::MoveTo(nsIFile *newParentDir, const char *newName)
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsLocalFile::Spawn(const char *args)
|
||||
nsLocalFile::Spawn(const char **args, PRUint32 count)
|
||||
{
|
||||
PRBool isFile;
|
||||
nsresult rv = IsFile(&isFile);
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
*
|
||||
* Contributor(s):
|
||||
* Mike Shaver <shaver@mozilla.org>
|
||||
* Christopher Blizzard <blizzard@mozilla.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
|
@ -34,6 +35,7 @@
|
|||
#include <errno.h>
|
||||
#include <utime.h>
|
||||
#include <dirent.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include "nsCRT.h"
|
||||
#include "nsCOMPtr.h"
|
||||
|
@ -42,6 +44,7 @@
|
|||
#include "nsILocalFile.h"
|
||||
#include "nsLocalFileUnix.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include "prproces.h"
|
||||
|
||||
// On some platforms file/directory name comparisons need to
|
||||
// be case-blind.
|
||||
|
@ -404,7 +407,17 @@ nsLocalFile::Append(const char *fragment)
|
|||
NS_IMETHODIMP
|
||||
nsLocalFile::Normalize()
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
char resolved_path[PATH_MAX];
|
||||
char *resolved_path_ptr = NULL;
|
||||
CHECK_mPath();
|
||||
resolved_path_ptr = realpath(mPath, resolved_path);
|
||||
// if there is an error, the return is null.
|
||||
if (resolved_path_ptr == NULL) {
|
||||
return NSRESULT_FOR_ERRNO();
|
||||
}
|
||||
// nsXPIDLCString will copy.
|
||||
mPath = resolved_path;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
|
@ -1065,9 +1078,43 @@ nsLocalFile::GetTarget(char **_retval)
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsLocalFile::Spawn(const char *args)
|
||||
nsLocalFile::Spawn(const char **args, PRUint32 count)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
CHECK_mPath();
|
||||
|
||||
// status from our create process
|
||||
PRStatus rv = PR_FAILURE;
|
||||
|
||||
// this is the argv that will hold the args that
|
||||
char ** my_argv = NULL;
|
||||
|
||||
// make sure that when we allocate we have 1 greater than the
|
||||
// count since we need to null terminate the list for the argv to
|
||||
// pass into PR_CreateProcessDetached
|
||||
my_argv = (char **)malloc(sizeof(char *) * (count + 2) );
|
||||
if (!my_argv) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
// copy the args
|
||||
PRUint32 i;
|
||||
for (i=0; i < count; i++) {
|
||||
my_argv[i+1] = (char *)args[i];
|
||||
}
|
||||
// we need to set argv[0] to the program name.
|
||||
my_argv[0] = (char *)(const char *)mPath;
|
||||
|
||||
// null terminate the array
|
||||
my_argv[count+1] = NULL;
|
||||
|
||||
rv = PR_CreateProcessDetached(mPath, my_argv, NULL, NULL);
|
||||
|
||||
// free up our argv
|
||||
free(my_argv);
|
||||
|
||||
if (PR_SUCCESS == rv)
|
||||
return NS_OK;
|
||||
else
|
||||
return NS_ERROR_FILE_EXECUTION_FAILED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
|
|
@ -1077,7 +1077,7 @@ nsLocalFile::MoveTo(nsIFile *newParentDir, const char *newName)
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsLocalFile::Spawn(const char *args)
|
||||
nsLocalFile::Spawn(const char **args, PRUint32 count)
|
||||
{
|
||||
PRBool isFile;
|
||||
nsresult rv = IsFile(&isFile);
|
||||
|
@ -1085,19 +1085,35 @@ nsLocalFile::Spawn(const char *args)
|
|||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
nsCString fileNameWithArgs(mResolvedPath);
|
||||
|
||||
if(args)
|
||||
{
|
||||
fileNameWithArgs.Append(" ");
|
||||
fileNameWithArgs.Append(args);
|
||||
// make sure that when we allocate we have 1 greater than the
|
||||
// count since we need to null terminate the list for the argv to
|
||||
// pass into PR_CreateProcessDetached
|
||||
char **my_argv = NULL;
|
||||
|
||||
my_argv = (char **)malloc(sizeof(char *) * (count + 2) );
|
||||
if (!my_argv) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
int execResult = WinExec( fileNameWithArgs, SW_NORMAL );
|
||||
if (execResult > 31)
|
||||
return NS_OK;
|
||||
// copy the args
|
||||
PRUint32 i;
|
||||
for (i=0; i < count; i++) {
|
||||
my_argv[i+1] = (char *)args[i];
|
||||
}
|
||||
// we need to set argv[0] to the program name.
|
||||
my_argv[0] = mResolvedPath;
|
||||
|
||||
// null terminate the array
|
||||
my_argv[count+1] = NULL;
|
||||
rv = PR_CreateProcessDetached(mResolvedPath, my_argv, NULL, NULL);
|
||||
|
||||
return NS_ERROR_FILE_EXECUTION_FAILED;
|
||||
// free up our argv
|
||||
nsAllocator::Free(my_argv);
|
||||
|
||||
if (PR_SUCCESS == rv)
|
||||
return NS_OK;
|
||||
else
|
||||
return NS_ERROR_FILE_EXECUTION_FAILED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
|
Загрузка…
Ссылка в новой задаче