tarcmd.cpp revision ff74d28041a2179e652244a3f7b64d34c2dfc87a
831b4c533723665e3a004ca13c9f413f4221ffbbvboxsync * IPRT - A mini TAR Command.
e64031e20c39650a7bc902a3e1aba613b9415deevboxsync * Copyright (C) 2010-2013 Oracle Corporation
831b4c533723665e3a004ca13c9f413f4221ffbbvboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
831b4c533723665e3a004ca13c9f413f4221ffbbvboxsync * available from http://www.virtualbox.org. This file is free software;
831b4c533723665e3a004ca13c9f413f4221ffbbvboxsync * you can redistribute it and/or modify it under the terms of the GNU
831b4c533723665e3a004ca13c9f413f4221ffbbvboxsync * General Public License (GPL) as published by the Free Software
831b4c533723665e3a004ca13c9f413f4221ffbbvboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
831b4c533723665e3a004ca13c9f413f4221ffbbvboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
831b4c533723665e3a004ca13c9f413f4221ffbbvboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
831b4c533723665e3a004ca13c9f413f4221ffbbvboxsync * The contents of this file may alternatively be used under the terms
831b4c533723665e3a004ca13c9f413f4221ffbbvboxsync * of the Common Development and Distribution License Version 1.0
831b4c533723665e3a004ca13c9f413f4221ffbbvboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
831b4c533723665e3a004ca13c9f413f4221ffbbvboxsync * VirtualBox OSE distribution, in which case the provisions of the
831b4c533723665e3a004ca13c9f413f4221ffbbvboxsync * CDDL are applicable instead of those of the GPL.
831b4c533723665e3a004ca13c9f413f4221ffbbvboxsync * You may elect to license modified versions of this file under the
831b4c533723665e3a004ca13c9f413f4221ffbbvboxsync * terms and conditions of either the GPL or the CDDL or both.
831b4c533723665e3a004ca13c9f413f4221ffbbvboxsync/*******************************************************************************
831b4c533723665e3a004ca13c9f413f4221ffbbvboxsync* Header Files *
831b4c533723665e3a004ca13c9f413f4221ffbbvboxsync*******************************************************************************/
831b4c533723665e3a004ca13c9f413f4221ffbbvboxsync/*******************************************************************************
831b4c533723665e3a004ca13c9f413f4221ffbbvboxsync* Defined Constants And Macros *
831b4c533723665e3a004ca13c9f413f4221ffbbvboxsync*******************************************************************************/
831b4c533723665e3a004ca13c9f413f4221ffbbvboxsync/*******************************************************************************
831b4c533723665e3a004ca13c9f413f4221ffbbvboxsync* Structures and Typedefs *
831b4c533723665e3a004ca13c9f413f4221ffbbvboxsync*******************************************************************************/
831b4c533723665e3a004ca13c9f413f4221ffbbvboxsync * IPRT TAR option structure.
831b4c533723665e3a004ca13c9f413f4221ffbbvboxsync /** The operation (Acdrtux or RTZIPTARCMD_OPT_DELETE). */
831b4c533723665e3a004ca13c9f413f4221ffbbvboxsync /** The long operation option name. */
831b4c533723665e3a004ca13c9f413f4221ffbbvboxsync /** The directory to change into when packing and unpacking. */
831b4c533723665e3a004ca13c9f413f4221ffbbvboxsync /** The tar file name. */
831b4c533723665e3a004ca13c9f413f4221ffbbvboxsync const char *pszFile;
831b4c533723665e3a004ca13c9f413f4221ffbbvboxsync /** Whether we're verbose or quiet. */
bool fPreserveOwner;
bool fPreserveGroup;
bool fNoModTime;
/** The compressor/decompressor method to employ (0, z or j). */
char chZipper;
const char *pszOwner;
const char *pszGroup;
bool fDisplayUtc;
const char *pszPrefix;
const char * const *papszFiles;
typedef RTEXITCODE (*PFNDOWITHMEMBER)(PRTZIPTARCMDOPS pOpts, RTVFSOBJ hVfsObj, const char *pszName, RTEXITCODE rcExit);
static bool rtZipTarCmdIsNameInArray(const char *pszName, const char * const *papszNames, uint32_t *piName)
if (piName)
int rc;
const char *pszError;
&hVfsIos,
&pszError);
&hVfsIos);
return RTEXITCODE_FAILURE;
return RTEXITCODE_SUCCESS;
if (!pbmFound)
char *pszName;
if (pbmFound)
return rcExit;
while (*pszName)
pszName++;
pszName++;
static RTEXITCODE rtZipTarQueryExtractOwner(PRTZIPTARCMDOPS pOpts, PCRTFSOBJINFO pOwner, const char *pszName, RTEXITCODE rcExit,
return rcExit;
static RTEXITCODE rtZipTarQueryExtractGroup(PRTZIPTARCMDOPS pOpts, PCRTFSOBJINFO pGroup, const char *pszName, RTEXITCODE rcExit,
return rcExit;
static RTEXITCODE rtZipTarCmdExtractFile(PRTZIPTARCMDOPS pOpts, RTVFSOBJ hVfsObj, RTEXITCODE rcExit,
uint32_t fOpen = RTFILE_O_READWRITE | RTFILE_O_DENY_WRITE | RTFILE_O_CREATE_REPLACE | RTFILE_O_ACCESS_ATTR_DEFAULT
rcExit = RTMsgErrorExit(RTEXITCODE_FAILURE, "%s: Error creating I/O stream for file: %Rrc", pszDst, rc);
return rcExit;
static RTEXITCODE rtZipTarCmdExtractCallback(PRTZIPTARCMDOPS pOpts, RTVFSOBJ hVfsObj, const char *pszName, RTEXITCODE rcExit)
if (!szTarget[0])
return RTMsgErrorExit(RTEXITCODE_FAILURE, "%s: Failed to construct destination path for: %Rrc", pszName, rc);
case RTFS_TYPE_FILE:
case RTFS_TYPE_DIRECTORY:
case RTFS_TYPE_SYMLINK:
case RTFS_TYPE_FIFO:
case RTFS_TYPE_DEV_CHAR:
case RTFS_TYPE_DEV_BLOCK:
case RTFS_TYPE_SOCKET:
case RTFS_TYPE_WHITEOUT:
rcExit = RTMsgErrorExit(RTEXITCODE_FAILURE, "%s: Error changing modification time: %Rrc.", pszName, rc);
fMode = (UnixInfo.Attr.fMode & (pOpts->fFileModeAndMask | RTFS_TYPE_MASK)) | pOpts->fFileModeOrMask;
return rcExit;
static RTEXITCODE rtZipTarCmdListCallback(PRTZIPTARCMDOPS pOpts, RTVFSOBJ hVfsObj, const char *pszName, RTEXITCODE rcExit)
return rcExit;
rcExit = RTMsgErrorExit(RTEXITCODE_FAILURE, "RTVfsObjQueryInfo returned %Rrc on '%s'", rc, pszName);
if (!pTime)
case RTFS_TYPE_DEV_CHAR:
case RTFS_TYPE_DEV_BLOCK:
if (pszLinkType)
szTarget);
pszName);
return rcExit;
" Compress/decompress the archive with bzip2.\n"
" Compress/decompress the archive with gzip.\n"
{ "--file-mode-and-mask", RTZIPTARCMD_OPT_FILE_MODE_AND_MASK, RTGETOPT_REQ_UINT32 | RTGETOPT_FLAG_OCT },
{ "--file-mode-or-mask", RTZIPTARCMD_OPT_FILE_MODE_OR_MASK, RTGETOPT_REQ_UINT32 | RTGETOPT_FLAG_OCT },
{ "--dir-mode-and-mask", RTZIPTARCMD_OPT_DIR_MODE_AND_MASK, RTGETOPT_REQ_UINT32 | RTGETOPT_FLAG_OCT },
{ "--dir-mode-or-mask", RTZIPTARCMD_OPT_DIR_MODE_OR_MASK, RTGETOPT_REQ_UINT32 | RTGETOPT_FLAG_OCT },
if (RTPermIsSuperUser())
switch (rc)
case RTZIPTARCMD_OPT_DELETE:
case RTZIPTARCMD_OPT_OWNER:
case RTZIPTARCMD_OPT_GROUP:
case RTZIPTARCMD_OPT_UTC:
case RTZIPTARCMD_OPT_PREFIX:
return RTEXITCODE_SUCCESS;
return RTEXITCODE_SUCCESS;
return RTMsgErrorExit(RTEXITCODE_FAILURE, "The use of --owner with %s has not implemented yet", Opts.pszOperation);
return RTMsgErrorExit(RTEXITCODE_FAILURE, "The use of --group with %s has not implemented yet", Opts.pszOperation);
case RTZIPTARCMD_OPT_DELETE:
return RTMsgErrorExit(RTEXITCODE_FAILURE, "The operation %s is not implemented yet", Opts.pszOperation);