GuestCtrlImplFile.cpp revision c089168ef1a0fde89a6501905daef3f37a153512
/* $Id: */
/** @file
* VirtualBox Guest Control - Guest file handling.
*/
/*
* Copyright (C) 2011 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
#include "GuestImpl.h"
#include "GuestCtrlImplPrivate.h"
#include "Global.h"
#include "ConsoleImpl.h"
#include "ProgressImpl.h"
#include "VMMDev.h"
#include "AutoCaller.h"
#include "Logging.h"
#ifdef VBOX_WITH_GUEST_CONTROL
#endif
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else /* VBOX_WITH_GUEST_CONTROL */
using namespace guestControl;
/* Do not allow anonymous executions (with system rights). */
return fileExistsInternal(aFile,
NULL /* rc */);
#endif
}
#ifdef VBOX_WITH_GUEST_CONTROL
HRESULT Guest::fileExistsInternal(IN_BSTR aFile, IN_BSTR aUserName, IN_BSTR aPassword, BOOL *aExists, int *pRC)
{
using namespace guestControl;
AutoCaller autoCaller(this);
try
{
/*
* Prepare tool command line.
*/
/* We need to get output which is machine-readable in form
* of "key=value\0..key=value\0\0". */
/* Only the actual file name to chekc is needed for now. */
/*
* Execute guest process.
*/
30 * 1000 /* Wait 30s for getting the process started. */,
{
/* Wait for process to exit ... */
if (!fCompleted)
if (fCompleted)
{
{
{
}
else
tr("Error %u while checking for existence of file \"%s\""),
}
}
else if (fCanceled)
tr("Checking for file existence was aborted"));
else
AssertReleaseMsgFailed(("Checking for file existence neither completed nor canceled!?\n"));
}
}
{
rc = E_OUTOFMEMORY;
}
return rc;
}
#endif /* VBOX_WITH_GUEST_CONTROL */
STDMETHODIMP Guest::FileQuerySize(IN_BSTR aFile, IN_BSTR aUserName, IN_BSTR aPassword, LONG64 *aSize)
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else /* VBOX_WITH_GUEST_CONTROL */
using namespace guestControl;
/* Do not allow anonymous executions (with system rights). */
return fileQuerySizeInternal(aFile,
NULL /* rc */);
#endif
}
#ifdef VBOX_WITH_GUEST_CONTROL
HRESULT Guest::fileQuerySizeInternal(IN_BSTR aFile, IN_BSTR aUserName, IN_BSTR aPassword, LONG64 *aSize, int *pRC)
{
using namespace guestControl;
AutoCaller autoCaller(this);
try
{
/*
* Prepare tool command line.
*/
/* We need to get output which is machine-readable in form
* of "key=value\0..key=value\0\0". */
/* Only the actual file name to chekc is needed for now. */
/*
* Execute guest process.
*/
30 * 1000 /* Wait 30s for getting the process started. */,
{
/* Wait for process to exit ... */
if (!fCompleted)
if (fCompleted)
{
{
{
if (uRetExitCode == 0)
{
/* Get file size from output stream. */
ULONG cbOutputData = 0;
int vrc = VINF_SUCCESS;
for (;;)
{
10 * 1000 /* Timeout in ms */,
/** @todo Do stream header validation! */
&& aOutputData.size())
{
tr("Query file size: Error while adding guest output to stream buffer for file \"%s\" (%Rrc)"),
}
else /* No more output! */
break;
}
{
if ( RT_SUCCESS(vrc)
|| vrc == VERR_MORE_DATA)
{
if (RT_SUCCESS(vrc))
else
tr("Query file size: Unable to retrieve file size for file \"%s\" (%Rrc)"),
}
else
tr("Query file size: Error while parsing guest output for file \"%s\" (%Rrc)"),
}
}
else
tr("Query file size: Error querying file size for file \"%s\" (exit code %u)"),
}
}
}
else if (fCanceled)
tr("Query file size: Checking for file size was aborted"));
else
AssertReleaseMsgFailed(("Checking for file size neither completed nor canceled!?\n"));
}
}
{
rc = E_OUTOFMEMORY;
}
return rc;
}
#endif /* VBOX_WITH_GUEST_CONTROL */