82391de567696f10b21a762fde6a06fe3c266d28vboxsync * DnD: URI list class.
82391de567696f10b21a762fde6a06fe3c266d28vboxsync * Copyright (C) 2014 Oracle Corporation
82391de567696f10b21a762fde6a06fe3c266d28vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
82391de567696f10b21a762fde6a06fe3c266d28vboxsync * available from http://www.virtualbox.org. This file is free software;
82391de567696f10b21a762fde6a06fe3c266d28vboxsync * you can redistribute it and/or modify it under the terms of the GNU
82391de567696f10b21a762fde6a06fe3c266d28vboxsync * General Public License (GPL) as published by the Free Software
82391de567696f10b21a762fde6a06fe3c266d28vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
82391de567696f10b21a762fde6a06fe3c266d28vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
82391de567696f10b21a762fde6a06fe3c266d28vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
82391de567696f10b21a762fde6a06fe3c266d28vboxsync/******************************************************************************
82391de567696f10b21a762fde6a06fe3c266d28vboxsync * Header Files *
82391de567696f10b21a762fde6a06fe3c266d28vboxsync ******************************************************************************/
7b4c4bb29760b28b5727231ad446462a5b0cc01avboxsync/* static */
7b4c4bb29760b28b5727231ad446462a5b0cc01avboxsync/** @todo Put this into an own class like DnDURIPath : public RTCString? */
7b4c4bb29760b28b5727231ad446462a5b0cc01avboxsync char *pszPathNew = RTPathJoinA(strBaseNew.c_str(), pszPathStart);
7b4c4bb29760b28b5727231ad446462a5b0cc01avboxsync char *pszPathURI = RTUriCreate("file" /* pszScheme */, "/" /* pszAuthority */,
7b4c4bb29760b28b5727231ad446462a5b0cc01avboxsync LogFlowFunc(("Rebasing \"%s\" to \"%s\"", strPath.c_str(), pszPathURI));
7b4c4bb29760b28b5727231ad446462a5b0cc01avboxsyncint DnDURIObject::Read(void *pvBuf, uint32_t cbToRead, uint32_t *pcbRead)
7b4c4bb29760b28b5727231ad446462a5b0cc01avboxsync /* pcbRead is optional. */
7b4c4bb29760b28b5727231ad446462a5b0cc01avboxsync /* Open files on the source with RTFILE_O_DENY_WRITE to prevent races
7b4c4bb29760b28b5727231ad446462a5b0cc01avboxsync * where the OS writes to the file while the destination side transfers
7b4c4bb29760b28b5727231ad446462a5b0cc01avboxsync * it over. */
7b4c4bb29760b28b5727231ad446462a5b0cc01avboxsync RTFILE_O_OPEN | RTFILE_O_READ | RTFILE_O_DENY_WRITE);
7b4c4bb29760b28b5727231ad446462a5b0cc01avboxsync rc = RTFileRead(u.m_hFile, pvBuf, cbToRead, &cbRead);
7b4c4bb29760b28b5727231ad446462a5b0cc01avboxsync /* End of file reached or error occurred? */
7b4c4bb29760b28b5727231ad446462a5b0cc01avboxsync LogFlowFunc(("Returning strSourcePath=%s, rc=%Rrc\n",
82391de567696f10b21a762fde6a06fe3c266d28vboxsyncint DnDURIList::appendPathRecursive(const char *pcszPath, size_t cbBaseLen,
82391de567696f10b21a762fde6a06fe3c266d28vboxsync int rc = RTPathQueryInfo(pcszPath, &objInfo, RTFSOBJATTRADD_NOTHING);
82391de567696f10b21a762fde6a06fe3c266d28vboxsync * These are the types we currently support. Symlinks are not directly
82391de567696f10b21a762fde6a06fe3c266d28vboxsync * supported. First the guest could be an OS which doesn't support it and
82391de567696f10b21a762fde6a06fe3c266d28vboxsync * second the symlink could point to a file which is out of the base tree.
82391de567696f10b21a762fde6a06fe3c266d28vboxsync * Both things are hard to support. For now we just copy the target file in
82391de567696f10b21a762fde6a06fe3c266d28vboxsync * this case.
7b4c4bb29760b28b5727231ad446462a5b0cc01avboxsync m_lstTree.append(DnDURIObject( RTFS_IS_DIRECTORY(objInfo.Attr.fMode)
7b4c4bb29760b28b5727231ad446462a5b0cc01avboxsync LogFlowFunc(("strSrcPath=%s, strDstPath=%s, fMode=0x%x, cbSize=%RU64, cbTotal=%zu\n",
82391de567696f10b21a762fde6a06fe3c266d28vboxsync pcszPath, &pcszPath[cbBaseLen], objInfo.Attr.fMode, cbSize, m_cbTotal));
82391de567696f10b21a762fde6a06fe3c266d28vboxsync /* We have to try to open even symlinks, cause they could
82391de567696f10b21a762fde6a06fe3c266d28vboxsync * be symlinks to directories. */
82391de567696f10b21a762fde6a06fe3c266d28vboxsync /* The following error happens when this was a symlink
82391de567696f10b21a762fde6a06fe3c266d28vboxsync * to an file or a regular file. */
82391de567696f10b21a762fde6a06fe3c266d28vboxsync /* Skip "." and ".." entries. */
401ce2099f0ede0091ea3f661331c6f1dd117d28vboxsync char *pszRecDir = RTPathJoinA(pcszPath, DirEntry.szName);
82391de567696f10b21a762fde6a06fe3c266d28vboxsync rc = appendPathRecursive(pszRecDir, cbBaseLen, fFlags);
401ce2099f0ede0091ea3f661331c6f1dd117d28vboxsync char *pszNewFile = RTPathJoinA(pcszPath, DirEntry.szName);
82391de567696f10b21a762fde6a06fe3c266d28vboxsync /* We need the size and the mode of the file. */
82391de567696f10b21a762fde6a06fe3c266d28vboxsync rc = RTPathQueryInfo(pszNewFile, &objInfo1, RTFSOBJATTRADD_NOTHING);
1eca9bc66f92b644829034ae391e6fc3591e93e0vboxsync if (rc == VERR_IS_A_DIRECTORY) /* Happens for symlinks. */
1eca9bc66f92b644829034ae391e6fc3591e93e0vboxsync else /* Handle symlink directories. */
1eca9bc66f92b644829034ae391e6fc3591e93e0vboxsync rc = appendPathRecursive(pszNewFile, cbBaseLen, fFlags);
7b4c4bb29760b28b5727231ad446462a5b0cc01avboxsync LogFlowFunc(("strSrcPath=%s, strDstPath=%s, fMode=0x%x, cbSize=%RU64, cbTotal=%zu\n",
82391de567696f10b21a762fde6a06fe3c266d28vboxsync pszNewFile, &pszNewFile[cbBaseLen], objInfo1.Attr.fMode, cbSize, m_cbTotal));
7b4c4bb29760b28b5727231ad446462a5b0cc01avboxsyncint DnDURIList::AppendNativePath(const char *pszPath, uint32_t fFlags)
ebcdaa5077bc9189c419330b1c84880018e3db99vboxsync RTPathChangeToUnixSlashes(pszPathNative, true /* fForce */);
ebcdaa5077bc9189c419330b1c84880018e3db99vboxsync char *pszPathURI = RTUriCreate("file" /* pszScheme */, "/" /* pszAuthority */,
ebcdaa5077bc9189c419330b1c84880018e3db99vboxsync pszPathNative, NULL /* pszQuery */, NULL /* pszFragment */);
7b4c4bb29760b28b5727231ad446462a5b0cc01avboxsyncint DnDURIList::AppendNativePathsFromList(const char *pszNativePaths, size_t cbNativePaths,
7b4c4bb29760b28b5727231ad446462a5b0cc01avboxsync AssertPtrReturn(pszNativePaths, VERR_INVALID_POINTER);
7b4c4bb29760b28b5727231ad446462a5b0cc01avboxsync AssertReturn(cbNativePaths, VERR_INVALID_PARAMETER);
7b4c4bb29760b28b5727231ad446462a5b0cc01avboxsync = RTCString(pszNativePaths, cbNativePaths - 1).split("\r\n");
7b4c4bb29760b28b5727231ad446462a5b0cc01avboxsync return AppendNativePathsFromList(lstPaths, fFlags);
7b4c4bb29760b28b5727231ad446462a5b0cc01avboxsyncint DnDURIList::AppendNativePathsFromList(const RTCList<RTCString> &lstNativePaths,
7b4c4bb29760b28b5727231ad446462a5b0cc01avboxsyncint DnDURIList::AppendURIPath(const char *pszURI, uint32_t fFlags)
924c248d11ce3849739cc64791d34564d68869cevboxsync /** @todo Check for string termination? */
7b4c4bb29760b28b5727231ad446462a5b0cc01avboxsync LogFlowFunc(("pszPath=%s, fFlags=0x%x\n", pszURI, fFlags));
82391de567696f10b21a762fde6a06fe3c266d28vboxsync /* Query the path component of a file URI. If this hasn't a
82391de567696f10b21a762fde6a06fe3c266d28vboxsync * file scheme NULL is returned. */
7b4c4bb29760b28b5727231ad446462a5b0cc01avboxsync char *pszFilePath = RTUriFilePath(pszURI, URI_FILE_FORMAT_AUTO);
82391de567696f10b21a762fde6a06fe3c266d28vboxsync /* Add the path to our internal file list (recursive in
82391de567696f10b21a762fde6a06fe3c266d28vboxsync * the case of a directory). */
924c248d11ce3849739cc64791d34564d68869cevboxsync size_t cbPathLen = RTPathStripTrailingSlash(pszFilePath);
8c71acd3714d92a0602a95d19fbb2aef0cf5fd5dvboxsync size_t cbBase = (fFlags & DNDURILIST_FLAGS_ABSOLUTE_PATHS)
8c71acd3714d92a0602a95d19fbb2aef0cf5fd5dvboxsync ? 0 /* Use start of path as root. */
924c248d11ce3849739cc64791d34564d68869cevboxsync LogFlowFunc(("pszFilePath=%s, pszFileName=%s, pszRoot=%s\n",
7b4c4bb29760b28b5727231ad446462a5b0cc01avboxsyncint DnDURIList::AppendURIPathsFromList(const char *pszURIPaths, size_t cbURIPaths,
7b4c4bb29760b28b5727231ad446462a5b0cc01avboxsync AssertPtrReturn(pszURIPaths, VERR_INVALID_POINTER);
7b4c4bb29760b28b5727231ad446462a5b0cc01avboxsync = RTCString(pszURIPaths, cbURIPaths - 1).split("\r\n");
7b4c4bb29760b28b5727231ad446462a5b0cc01avboxsyncint DnDURIList::AppendURIPathsFromList(const RTCList<RTCString> &lstURI,
7b4c4bb29760b28b5727231ad446462a5b0cc01avboxsyncint DnDURIList::RootFromURIData(const void *pvData, size_t cbData,
7b4c4bb29760b28b5727231ad446462a5b0cc01avboxsync RTCString(static_cast<const char*>(pvData), cbData - 1).split("\r\n");
7b4c4bb29760b28b5727231ad446462a5b0cc01avboxsync /* Query the path component of a file URI. If this hasn't a
7b4c4bb29760b28b5727231ad446462a5b0cc01avboxsync * file scheme, NULL is returned. */
7b4c4bb29760b28b5727231ad446462a5b0cc01avboxsync LogFlowFunc(("pszURI=%s, pszFilePath=%s\n", pszURI, pszFilePath));
7b4c4bb29760b28b5727231ad446462a5b0cc01avboxsync rc = DnDPathSanitize(pszFilePath, strlen(pszFilePath));
2ad9f8a731c73f6ac74044d42d47bbaf6f44a566vboxsyncRTCString DnDURIList::RootToString(const RTCString &strBasePath /* = "" */,