GuestDirectoryImpl.cpp revision 510567648d46488f4166e5f69ffffe3eeeeec4d9
352bb6b9d2fa1f7df7797f50c58e297ac37059a2vboxsync * VirtualBox Main - Guest directory handling.
352bb6b9d2fa1f7df7797f50c58e297ac37059a2vboxsync * Copyright (C) 2012-2013 Oracle Corporation
352bb6b9d2fa1f7df7797f50c58e297ac37059a2vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
352bb6b9d2fa1f7df7797f50c58e297ac37059a2vboxsync * available from http://www.virtualbox.org. This file is free software;
352bb6b9d2fa1f7df7797f50c58e297ac37059a2vboxsync * you can redistribute it and/or modify it under the terms of the GNU
352bb6b9d2fa1f7df7797f50c58e297ac37059a2vboxsync * General Public License (GPL) as published by the Free Software
352bb6b9d2fa1f7df7797f50c58e297ac37059a2vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
352bb6b9d2fa1f7df7797f50c58e297ac37059a2vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
352bb6b9d2fa1f7df7797f50c58e297ac37059a2vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
352bb6b9d2fa1f7df7797f50c58e297ac37059a2vboxsync/*******************************************************************************
352bb6b9d2fa1f7df7797f50c58e297ac37059a2vboxsync* Header Files *
352bb6b9d2fa1f7df7797f50c58e297ac37059a2vboxsync*******************************************************************************/
352bb6b9d2fa1f7df7797f50c58e297ac37059a2vboxsync// constructor / destructor
352bb6b9d2fa1f7df7797f50c58e297ac37059a2vboxsync/////////////////////////////////////////////////////////////////////////////
6da8aad9b9f0e2aa239259658e3d82073f5761e4vboxsync// public initializer/uninitializer for internal purposes only
6da8aad9b9f0e2aa239259658e3d82073f5761e4vboxsync/////////////////////////////////////////////////////////////////////////////
6da8aad9b9f0e2aa239259658e3d82073f5761e4vboxsync const Utf8Str &strPath, const Utf8Str &strFilter, uint32_t uFlags)
6da8aad9b9f0e2aa239259658e3d82073f5761e4vboxsync LogFlowThisFunc(("strPath=%s, strFilter=%s, uFlags=%x\n",
6da8aad9b9f0e2aa239259658e3d82073f5761e4vboxsync /* Enclose the state transition NotReady->InInit->Ready. */
6da8aad9b9f0e2aa239259658e3d82073f5761e4vboxsync /* Start the directory process on the guest. */
6da8aad9b9f0e2aa239259658e3d82073f5761e4vboxsync procInfo.mName = Utf8StrFmt(tr("Reading directory \"%s\"", strPath.c_str()));
6da8aad9b9f0e2aa239259658e3d82073f5761e4vboxsync procInfo.mTimeoutMS = 5 * 60 * 1000; /* 5 minutes timeout. */
6da8aad9b9f0e2aa239259658e3d82073f5761e4vboxsync procInfo.mArguments.push_back(Utf8Str("--machinereadable"));
6da8aad9b9f0e2aa239259658e3d82073f5761e4vboxsync /* We want the long output format which contains all the object details. */
6da8aad9b9f0e2aa239259658e3d82073f5761e4vboxsync#if 0 /* Flags are not supported yet. */
6da8aad9b9f0e2aa239259658e3d82073f5761e4vboxsync procInfo.mArguments.push_back(Utf8Str("--nosymlinks")); /** @todo What does GNU here? */
6da8aad9b9f0e2aa239259658e3d82073f5761e4vboxsync /** @todo Recursion support? */
6da8aad9b9f0e2aa239259658e3d82073f5761e4vboxsync procInfo.mArguments.push_back(strPath); /* The directory we want to open. */
6da8aad9b9f0e2aa239259658e3d82073f5761e4vboxsync * Start the process asynchronously and keep it around so that we can use
6da8aad9b9f0e2aa239259658e3d82073f5761e4vboxsync * it later in subsequent read() calls.
6da8aad9b9f0e2aa239259658e3d82073f5761e4vboxsync * Note: No guest rc available because operation is asynchronous.
6da8aad9b9f0e2aa239259658e3d82073f5761e4vboxsync int rc = mData.mProcessTool.Init(mData.mSession, procInfo,
6da8aad9b9f0e2aa239259658e3d82073f5761e4vboxsync /* Confirm a successful initialization when it's the case. */
6da8aad9b9f0e2aa239259658e3d82073f5761e4vboxsync * Uninitializes the instance.
6da8aad9b9f0e2aa239259658e3d82073f5761e4vboxsync * Called from FinalRelease().
6da8aad9b9f0e2aa239259658e3d82073f5761e4vboxsync /* Enclose the state transition Ready->InUninit->NotReady. */
6da8aad9b9f0e2aa239259658e3d82073f5761e4vboxsync// implementation of public getters/setters for attributes
6da8aad9b9f0e2aa239259658e3d82073f5761e4vboxsync/////////////////////////////////////////////////////////////////////////////
6da8aad9b9f0e2aa239259658e3d82073f5761e4vboxsyncSTDMETHODIMP GuestDirectory::COMGETTER(DirectoryName)(BSTR *aName)
6da8aad9b9f0e2aa239259658e3d82073f5761e4vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
6da8aad9b9f0e2aa239259658e3d82073f5761e4vboxsyncSTDMETHODIMP GuestDirectory::COMGETTER(Filter)(BSTR *aFilter)
6da8aad9b9f0e2aa239259658e3d82073f5761e4vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
6da8aad9b9f0e2aa239259658e3d82073f5761e4vboxsync// private methods
6da8aad9b9f0e2aa239259658e3d82073f5761e4vboxsync/////////////////////////////////////////////////////////////////////////////
6da8aad9b9f0e2aa239259658e3d82073f5761e4vboxsync// implementation of public methods
6da8aad9b9f0e2aa239259658e3d82073f5761e4vboxsync/////////////////////////////////////////////////////////////////////////////
6da8aad9b9f0e2aa239259658e3d82073f5761e4vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
6da8aad9b9f0e2aa239259658e3d82073f5761e4vboxsync int rc = mData.mSession->directoryRemoveFromList(this);
6da8aad9b9f0e2aa239259658e3d82073f5761e4vboxsync rc = mData.mProcessTool.Terminate(30 * 1000, &guestRc);
6da8aad9b9f0e2aa239259658e3d82073f5761e4vboxsync hr = GuestProcess::setErrorExternal(this, guestRc);
6da8aad9b9f0e2aa239259658e3d82073f5761e4vboxsync /* Silently skip old Guest Additions which do not support killing the
6da8aad9b9f0e2aa239259658e3d82073f5761e4vboxsync * the guest directory handling process. */
6da8aad9b9f0e2aa239259658e3d82073f5761e4vboxsync tr("Terminating open guest directory \"%s\" failed: %Rrc"),
6da8aad9b9f0e2aa239259658e3d82073f5761e4vboxsync * Release autocaller before calling uninit.
6da8aad9b9f0e2aa239259658e3d82073f5761e4vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */
6da8aad9b9f0e2aa239259658e3d82073f5761e4vboxsyncSTDMETHODIMP GuestDirectory::Read(IFsObjInfo **aInfo)
6da8aad9b9f0e2aa239259658e3d82073f5761e4vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
6da8aad9b9f0e2aa239259658e3d82073f5761e4vboxsync int rc = mData.mProcessTool.WaitEx(GUESTPROCESSTOOL_FLAG_STDOUT_BLOCK,
6da8aad9b9f0e2aa239259658e3d82073f5761e4vboxsync * Note: The guest process can still be around to serve the next
6da8aad9b9f0e2aa239259658e3d82073f5761e4vboxsync * upcoming stream block next time.
6da8aad9b9f0e2aa239259658e3d82073f5761e4vboxsync rc = mData.mProcessTool.TerminatedOk(NULL /* Exit code */);
6da8aad9b9f0e2aa239259658e3d82073f5761e4vboxsync /* Create the object. */
6da8aad9b9f0e2aa239259658e3d82073f5761e4vboxsync /* Return info object to the caller. */
6da8aad9b9f0e2aa239259658e3d82073f5761e4vboxsync /* Nothing to read anymore. Tell the caller. */
6da8aad9b9f0e2aa239259658e3d82073f5761e4vboxsync if (RT_FAILURE(rc)) /** @todo Add more errors here. */
6da8aad9b9f0e2aa239259658e3d82073f5761e4vboxsync hr = GuestProcess::setErrorExternal(this, guestRc);
6da8aad9b9f0e2aa239259658e3d82073f5761e4vboxsync hr = setError(VBOX_E_IPRT_ERROR, tr("Reading directory \"%s\" failed: Unable to read / access denied"),
6da8aad9b9f0e2aa239259658e3d82073f5761e4vboxsync hr = setError(VBOX_E_IPRT_ERROR, tr("Reading directory \"%s\" failed: Path not found"),
6da8aad9b9f0e2aa239259658e3d82073f5761e4vboxsync /* See SDK reference. */
6da8aad9b9f0e2aa239259658e3d82073f5761e4vboxsync hr = setError(VBOX_E_OBJECT_NOT_FOUND, tr("No more entries for directory \"%s\""),
6da8aad9b9f0e2aa239259658e3d82073f5761e4vboxsync hr = setError(VBOX_E_IPRT_ERROR, tr("Error while reading directory \"%s\": %Rrc\n"),
6da8aad9b9f0e2aa239259658e3d82073f5761e4vboxsync#endif /* VBOX_WITH_GUEST_CONTROL */