VirtualBox

Changeset 93145 in vbox for trunk


Ignore:
Timestamp:
Jan 8, 2022 3:07:46 AM (3 years ago)
Author:
vboxsync
Message:

Add/os2: Made the installer start in a --dry-run mode and require a -i/--do-install parameter before it actually does anything. Fixed sharing violation issue clearing the readonly bit.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/os2/VBoxOs2AdditionsInstall.cpp

    r93144 r93145  
    8484/** Verbose or quiet. */
    8585static bool         g_fVerbose                      = true;
     86/** Whether this is a real run (true) or just a trial. */
     87static bool         g_fRealRun                      = false;
    8688
    8789/** The standard output handle. */
     
    13271329
    13281330/**
     1331 * Tells the loader to cache all the pages in @a pszFile and close it, so that
     1332 * we can modify or replace it.
     1333 */
     1334static void CacheLdrFile(const char *pszFile)
     1335{
     1336    if (g_fVerbose)
     1337        DoWriteNStr(g_hStdOut, RT_STR_TUPLE("info: Sharing violation - applying DosReplaceModule...\r\n"));
     1338
     1339    APIRET rc = DosReplaceModule(pszFile, NULL, NULL);
     1340    if (rc != NO_ERROR)
     1341        ApiErrorN(rc, 3, "DosReplaceModule(\"", pszFile, "\",,)");
     1342}
     1343
     1344
     1345/**
    13291346 * Worker for CopyFiles that handles one copying operation.
    13301347 */
    13311348static RTEXITCODE CopyOneFile(const char *pszSrc, const char *pszDst)
    13321349{
     1350    FILESTATUS3 FileSts;
    13331351    if (g_fVerbose)
    13341352        WriteStrings(g_hStdOut, "info: Copying \"", pszSrc, "\" to \"", pszDst, "\"...\r\n", NULL);
    13351353
    1336     /* Make sure the destination file isn't read-only before attempting to copying it. */
    1337     FILESTATUS3 FileSts;
    1338     APIRET rc = DosQueryPathInfo(pszDst, FIL_STANDARD, &FileSts, sizeof(FileSts));
    1339     if (rc == NO_ERROR && (FileSts.attrFile & FILE_READONLY))
    1340     {
    1341         FileSts.attrFile &= ~FILE_READONLY;
    1342 
    1343         /* Don't update the timestamps: */
    1344         *(USHORT *)&FileSts.fdateCreation   = 0;
    1345         *(USHORT *)&FileSts.ftimeCreation   = 0;
    1346         *(USHORT *)&FileSts.fdateLastAccess = 0;
    1347         *(USHORT *)&FileSts.ftimeLastAccess = 0;
    1348         *(USHORT *)&FileSts.fdateLastWrite  = 0;
    1349         *(USHORT *)&FileSts.ftimeLastWrite  = 0;
    1350 
    1351         rc = DosSetPathInfo(pszDst, FIL_STANDARD, &FileSts, sizeof(FileSts), 0 /*fOptions*/);
    1352         if (rc != NO_ERROR)
    1353             ApiErrorN(rc, 3, "DosSetPathInfo(\"", pszDst, "\",~READONLY,)");
    1354     }
    1355 
    1356     /* Do the copying. */
    1357     rc = DosCopy(pszSrc, pszDst, DCPY_EXISTING);
    1358     if (rc == NO_ERROR)
    1359         return RTEXITCODE_SUCCESS;
    1360     if (rc != ERROR_SHARING_VIOLATION)
     1354    if (g_fRealRun)
     1355    {
     1356        /* Make sure the destination file isn't read-only before attempting to copying it. */
     1357        APIRET rc = DosQueryPathInfo(pszDst, FIL_STANDARD, &FileSts, sizeof(FileSts));
     1358        if (rc == NO_ERROR && (FileSts.attrFile & FILE_READONLY))
     1359        {
     1360            FileSts.attrFile &= ~FILE_READONLY;
     1361
     1362            /* Don't update the timestamps: */
     1363            *(USHORT *)&FileSts.fdateCreation   = 0;
     1364            *(USHORT *)&FileSts.ftimeCreation   = 0;
     1365            *(USHORT *)&FileSts.fdateLastAccess = 0;
     1366            *(USHORT *)&FileSts.ftimeLastAccess = 0;
     1367            *(USHORT *)&FileSts.fdateLastWrite  = 0;
     1368            *(USHORT *)&FileSts.ftimeLastWrite  = 0;
     1369
     1370            rc = DosSetPathInfo(pszDst, FIL_STANDARD, &FileSts, sizeof(FileSts), 0 /*fOptions*/);
     1371            if (rc == ERROR_SHARING_VIOLATION)
     1372            {
     1373                CacheLdrFile(pszDst);
     1374                rc = DosSetPathInfo(pszDst, FIL_STANDARD, &FileSts, sizeof(FileSts), 0 /*fOptions*/);
     1375            }
     1376
     1377            if (rc != NO_ERROR)
     1378                ApiErrorN(rc, 3, "DosSetPathInfo(\"", pszDst, "\",~READONLY,)");
     1379        }
     1380
     1381        /* Do the copying. */
     1382        rc = DosCopy(pszSrc, pszDst, DCPY_EXISTING);
     1383        if (rc == NO_ERROR)
     1384            return RTEXITCODE_SUCCESS;
     1385        if (rc != ERROR_SHARING_VIOLATION)
     1386            return ApiErrorN(rc, 3, "Failed copying to \"", pszDst, "\"");
     1387
     1388        CacheLdrFile(pszDst);
     1389        rc = DosCopy(pszSrc, pszDst, DCPY_EXISTING);
     1390        if (rc == NO_ERROR)
     1391            return RTEXITCODE_SUCCESS;
    13611392        return ApiErrorN(rc, 3, "Failed copying to \"", pszDst, "\"");
    1362 
    1363     if (g_fVerbose)
    1364         DoWriteNStr(g_hStdOut, RT_STR_TUPLE("info: Sharing violation - applying DosReplaceModule...\r\n"));
    1365     rc = DosReplaceModule(pszDst, NULL, NULL);
    1366     if (rc != NO_ERROR)
    1367         ApiErrorN(rc, 3, "DosReplaceModule(\"", pszDst, "\",,)");
    1368 
    1369     rc = DosCopy(pszSrc, pszDst, DCPY_EXISTING);
    1370     if (rc == NO_ERROR)
    1371         return RTEXITCODE_SUCCESS;
    1372     return ApiErrorN(rc, 3, "Failed copying to \"", pszDst, "\"");
     1393    }
     1394    /*
     1395     * Dry run: just check that the source file exists.
     1396     */
     1397    else
     1398    {
     1399        APIRET rc = DosQueryPathInfo(pszSrc, FIL_STANDARD, &FileSts, sizeof(FileSts));
     1400        if (rc == NO_ERROR)
     1401            return RTEXITCODE_SUCCESS;
     1402        return ApiErrorN(rc, 3, "DosQueryPathInfo failed on \"", pszSrc, "\"");
     1403    }
    13731404}
    13741405
     
    13791410static RTEXITCODE CopyFiles(void)
    13801411{
    1381     /*
    1382      * Create the install directory.  We do this from the root up as that is
    1383      * a nice feature and saves us dealing with trailing slash troubles.
    1384      */
    1385     char *psz = g_szDstPath;
    1386     if (psz[1] == ':' && RTPATH_IS_SLASH(psz[2]))
    1387         psz += 3;
    1388     else if (psz[1] == ':')
    1389         psz += 2;
    1390     else
    1391         return ApiError("Unexpected condition", __LINE__);
    1392 
    1393     for (;;)
    1394     {
    1395         char ch;
    1396         while ((ch = *psz) != '\0' && !RTPATH_IS_SLASH(ch))
    1397             psz++;
    1398         if (ch != '\0')
    1399             *psz = '\0';
    1400         APIRET rc = DosMkDir(g_szDstPath, 0);
    1401         if (rc != NO_ERROR && rc != ERROR_ACCESS_DENIED /*HPFS*/ && rc != ERROR_ALREADY_EXISTS /*what one would expect*/)
    1402             return ApiErrorN(rc, 3, "DosMkDir(\"", g_szDstPath, "\")");
    1403         if (ch == '\0')
    1404             break;
    1405         *psz++ = ch;
    1406         while ((ch = *psz) != '\0' && RTPATH_IS_SLASH(ch))
    1407             psz++;
    1408         if (ch == '\0')
    1409             break;
     1412    if (g_fRealRun)
     1413    {
     1414        /*
     1415         * Create the install directory.  We do this from the root up as that is
     1416         * a nice feature and saves us dealing with trailing slash troubles.
     1417         */
     1418        char *psz = g_szDstPath;
     1419        if (psz[1] == ':' && RTPATH_IS_SLASH(psz[2]))
     1420            psz += 3;
     1421        else if (psz[1] == ':')
     1422            psz += 2;
     1423        else
     1424            return ApiError("Unexpected condition", __LINE__);
     1425
     1426        for (;;)
     1427        {
     1428            char ch;
     1429            while ((ch = *psz) != '\0' && !RTPATH_IS_SLASH(ch))
     1430                psz++;
     1431            if (ch != '\0')
     1432                *psz = '\0';
     1433            APIRET rc = DosMkDir(g_szDstPath, 0);
     1434            if (rc != NO_ERROR && rc != ERROR_ACCESS_DENIED /*HPFS*/ && rc != ERROR_ALREADY_EXISTS /*what one would expect*/)
     1435                return ApiErrorN(rc, 3, "DosMkDir(\"", g_szDstPath, "\")");
     1436            if (ch == '\0')
     1437                break;
     1438            *psz++ = ch;
     1439            while ((ch = *psz) != '\0' && RTPATH_IS_SLASH(ch))
     1440                psz++;
     1441            if (ch == '\0')
     1442                break;
     1443        }
    14101444    }
    14111445
     
    15081542        "\r\n"
    15091543        "Options:\r\n"
     1544        "  -i, --do-install         / -z, --dry-run\r\n"
     1545        "      Controls whether to do a real install or not.  Default: --dry-run\r\n"
    15101546        "  -s<path>, --source[=]<path>\r\n"
    15111547        "      Specifies where the files to install are.  Default: Same as installer\r\n"
     
    16811717                     || MatchOptWord(&pszArgs, RT_STR_TUPLE("source"), true))
    16821718                ch = 's';
     1719            else if (MatchOptWord(&pszArgs, RT_STR_TUPLE("do-install")))
     1720                ch = 'i';
     1721            else if (MatchOptWord(&pszArgs, RT_STR_TUPLE("dry-run")))
     1722                ch = 'z';
    16831723            else if (MatchOptWord(&pszArgs, RT_STR_TUPLE("shared-folders")))
    16841724                ch = 'f';
     
    17511791                    break;
    17521792
     1793                case 'i':
     1794                    g_fRealRun = true;
     1795                    break;
     1796
     1797                case 'z':
     1798                    g_fRealRun = false;
     1799                    break;
     1800
    17531801#define SKIP_OPT_CASES(a_chSkip, a_chDontSkip, a_fFlag) \
    17541802                case a_chDontSkip: g_fSkipMask &= ~(a_fFlag); break; \
     
    18091857    if (rcExit == RTEXITCODE_SUCCESS)
    18101858        rcExit = CopyFiles();
    1811     if (rcExit == RTEXITCODE_SUCCESS)
    1812         rcExit = WriteConfigSys();
    1813     if (rcExit == RTEXITCODE_SUCCESS)
    1814         rcExit = WriteStartupCmd();
    1815 
     1859    if (g_fRealRun)
     1860    {
     1861        if (rcExit == RTEXITCODE_SUCCESS)
     1862            rcExit = WriteConfigSys();
     1863        if (rcExit == RTEXITCODE_SUCCESS)
     1864            rcExit = WriteStartupCmd();
     1865
     1866        /*
     1867         * Status summary.
     1868         */
     1869        if (rcExit == RTEXITCODE_SUCCESS)
     1870            WriteStrings(g_hStdOut, "info: Installation successful\r\n", NULL);
     1871        else
     1872            WriteStrings(g_hStdErr, "info: Installation failed!\r\n", NULL);
     1873    }
     1874    else if (rcExit == RTEXITCODE_SUCCESS)
     1875        WriteStrings(g_hStdOut, "info: Trial run successful\r\n", NULL);
     1876    else
     1877        WriteStrings(g_hStdErr, "info: Trial run failed!\r\n", NULL);
    18161878    return rcExit;
    18171879}
Note: See TracChangeset for help on using the changeset viewer.

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