VirtualBox

Changeset 33885 in vbox


Ignore:
Timestamp:
Nov 9, 2010 10:28:35 AM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
67533
Message:

VBoxService/Toolbox: Updated vbox_mkdir.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/common/VBoxService/VBoxServiceToolBox.cpp

    r33863 r33885  
    146146     bool fVerbose = false;
    147147
    148      char *pszDir = NULL;
    149      RTFMODE fMode = 0; /** @todo Get standard mode from umask? */
     148     char szDir[RTPATH_MAX];
     149     RTFMODE newMode = 0;
     150     RTFMODE fileMode = RTFS_UNIX_MASK | RTFS_TYPE_DIRECTORY;
    150151
    151152     while (   (ch = RTGetOpt(&GetState, &ValueUnion))
     
    160161
    161162             case 'm':
    162                  /* Ignore by now. */
     163                 rc = RTStrToUInt32Ex(ValueUnion.psz, NULL, 8 /* Base */, &newMode);
     164                 if (RT_FAILURE(rc)) /* Only octet based values supported right now! */
     165                     VBoxServiceVerbose(0, "mkdir: Mode flag strings not implemented yet!\n");
    163166                 break;
    164167
     
    169172             case VINF_GETOPT_NOT_OPTION:
    170173             {
    171                  pszDir = RTPathAbsDup(ValueUnion.psz);
    172                  if (!pszDir)
    173                      rc = VERR_NO_MEMORY;
     174                 rc = RTPathAbs(ValueUnion.psz, szDir, sizeof(szDir));
     175                 if (RT_FAILURE(rc))
     176                     VBoxServiceError("mkdir: Could not build absolute directory!\n");
    174177                 break;
    175178             }
     
    182185     if (RT_SUCCESS(rc))
    183186     {
     187         if (fMakeParentDirs || newMode)
     188         {
     189#ifndef RT_OS_WINDOWS
     190             mode_t umaskMode = umask(0); /* Get current umask. */
     191             if (newMode)
     192             {
     193                 fileMode |= newMode;
     194             }
     195             else
     196                 fileMode |= S_IRWXUGO & ~umaskMode;
     197#endif
     198         }
     199
    184200         rc = fMakeParentDirs ?
    185                 RTDirCreateFullPath(pszDir, fMode)
    186               : RTDirCreate(pszDir, fMode);
     201                RTDirCreateFullPath(szDir, fileMode)
     202              : RTDirCreate(szDir, fileMode);
    187203
    188204         if (RT_SUCCESS(rc) && fVerbose)
    189              VBoxServiceVerbose(0, "mkdir: Created directory '%s'\n", pszDir);
     205             VBoxServiceVerbose(0, "mkdir: Created directory '%s', mode 0x%RTfmode\n", szDir, fileMode);
    190206         else if (RT_FAILURE(rc)) /** @todo Add a switch with more helpful error texts! */
    191             VBoxServiceError("mkdir: Could not create directory, rc=%Rrc\n", rc);
     207         {
     208             PCRTSTATUSMSG pMsg = RTErrGet(rc);
     209             if (pMsg)
     210                 VBoxServiceError("mkdir: Could not create directory: %s\n", pMsg->pszMsgFull);
     211             else
     212                 VBoxServiceError("mkdir: Could not create directory, rc=%Rrc\n", rc);
     213         }
     214
    192215     }
    193      else
     216     else if (fVerbose)
    194217         VBoxServiceError("mkdir: Failed with rc=%Rrc\n", rc);
    195      if (pszDir)
    196          RTStrFree(pszDir);
    197218     return rc;
    198219}
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette