Changeset 1472


Ignore:
Timestamp:
Oct 19, 2009, 7:43:42 PM (16 years ago)
Author:
Steven Levine
Message:

Correct docopyf regression which caused move to same volume to fail with access denied

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/HISTORY

    r1470 r1472  
    1313 o Avoid traps when changing tree container display style
    1414 o Restore missing drives to drive list dropdown
     15 o Correct docopyf regression which caused move to same volume to fail with access denied
    1516
    16173.17
  • trunk/dll/copyf.c

    r1469 r1472  
    1212  14 Oct 02 SHL Drop obsolete debug code
    1313  10 Nov 02 SHL docopyf - don't forget to terminate longname
    14                 optimize longname logic
     14                optimize longname logic
    1515  01 Aug 04 SHL Rework lstrip/rstrip usage
    1616  28 May 05 SHL Drop debug code
     
    2525  13 Jul 09 SHL Drop obsolete code
    2626  22 Jul 09 GKY Delete .LONGNAME EA if it becomes the filename on a copy or move.
     27  19 Oct 09 SHL Correct copyf regression when moving to save volume
    2728
    2829***********************************************************************/
     
    4647#include "arccnrs.h"
    4748#include "fm3str.h"
    48 #include "errutil.h"                    // Dos_Error...
    49 #include "strutil.h"                    // GetPString
     49#include "errutil.h"                    // Dos_Error...
     50#include "strutil.h"                    // GetPString
    5051#include "copyf.h"
    51 #include "literal.h"                    // fixup
     52#include "literal.h"                    // fixup
    5253#include "misc.h"                       // Broadcast
    5354#include "valid.h"                      // MakeFullName
    5455#include "wrappers.h"                   // xDosSetPathInfo
    5556#include "strips.h"                     // bstrip
    56 #include "fortify.h"                   
    57 #include "pathutil.h"                   // AddBackslashToPath
     57#include "fortify.h"
     58#include "pathutil.h"                   // AddBackslashToPath
    5859
    5960static PSZ pszSrcFile = __FILE__;
     
    6768#ifndef WinMoveObject
    6869HOBJECT APIENTRY WinMoveObject(HOBJECT hObjectofObject,
    69                                HOBJECT hObjectofDest, ULONG ulReserved);
     70                               HOBJECT hObjectofDest, ULONG ulReserved);
    7071#endif
    7172#ifndef WinCopyObject
    7273HOBJECT APIENTRY WinCopyObject(HOBJECT hObjectofObject,
    73                                HOBJECT hObjectofDest, ULONG ulReserved);
     74                               HOBJECT hObjectofDest, ULONG ulReserved);
    7475#endif
    7576
    76 char *MakeTempName(char *buffer, char *temproot, INT type)
     77/**
     78 * Make temporary file name
     79 * @param buffer is input directory name and output file name buffer
     80 * @param temproot is filename root used by type 2
     81 * @param type is name style
     82 * @return pointer to name in buffer or NULL if failed
     83 * @note not MT safe
     84 */
     85
     86PSZ MakeTempName(PSZ buffer, PSZ temproot, INT type)
    7787{
    7888  FILESTATUS3 fs3;
    7989  APIRET rc;
    80   char *p, *o;
    81 
    82   if (strlen(buffer) > 3) // && buffer[strlen(buffer) - 1] != '\\')
     90  PSZ p;
     91  PSZ o;
     92
     93  if (strlen(buffer) > 3)
    8394    AddBackslashToPath(buffer);
    84     //strcat(buffer, "\\");
    8595  p = o = buffer + strlen(buffer);
    8696  switch (type) {
     
    115125      (*p)++;
    116126      while (strchr("*?<>\":/\\|+=;,[]. ", *p))
    117         (*p)++;
     127        (*p)++;
    118128      *p = toupper(*p);
    119129    }
     
    121131      p--;
    122132      if (p >= o && *p == '.')
    123         p--;
     133        p--;
    124134      goto Loop;
    125135    }
     
    151161  f = oldname + (f - buffer);
    152162  strupr(buffer);
    153   while (*f == '.')                     /* skip leading '.'s */
    154     f++;
     163  while (*f == '.')
     164    f++;                // skip leading '.'s
    155165  s = f;
    156   while (*f && *f != '.' && f < s + 8) {        /* skip past rootname */
     166  // skip past rootname
     167  while (*f && *f != '.' && f < s + 8) {
    157168    *p = toupper(*f);
    158169    p++;
     
    209220      (*p)++;
    210221      while (strchr("*?<>\":/\\|+=;,[]. ", *p))
    211         (*p)++;
     222        (*p)++;
    212223      *p = toupper(*p);
    213224    }
     
    215226      p--;
    216227      if (p >= o && *p == '.')
    217         p--;
     228        p--;
    218229      goto Loop;
    219230    }
     
    243254    while (*value) {
    244255      if (*value == '/')
    245         *value = '\\';
     256        *value = '\\';
    246257      value++;
    247258    }
     
    260271      pfealist = xmallocz(1536, pszSrcFile, __LINE__);
    261272      if (pfealist) {
    262         pfealist->cbList = 1024;
    263         eaop.fpGEA2List = pgealist;
    264         eaop.fpFEA2List = pfealist;
    265         eaop.oError = 0L;
    266         DosError(FERR_DISABLEHARDERR);
    267         rc = DosQueryPathInfo(oldname,
    268                               FIL_QUERYEASFROMLIST,
    269                               (PVOID) & eaop, (ULONG) sizeof(EAOP2));
    270         if (!rc) {
    271           pfea = &eaop.fpFEA2List->list[0];
    272           value = pfea->szName + pfea->cbName + 1;
    273           value[pfea->cbValue] = 0;
    274           if (*(USHORT *) value == EAT_ASCII)
    275             strncat(longname,
    276                     value + (sizeof(USHORT) * 2),
    277                     CCHMAXPATH - strlen(longname));
    278           longname[CCHMAXPATH - 1] = 0;
    279         }
    280         free(pfealist);
     273        pfealist->cbList = 1024;
     274        eaop.fpGEA2List = pgealist;
     275        eaop.fpFEA2List = pfealist;
     276        eaop.oError = 0L;
     277        DosError(FERR_DISABLEHARDERR);
     278        rc = DosQueryPathInfo(oldname,
     279                              FIL_QUERYEASFROMLIST,
     280                              (PVOID) & eaop, (ULONG) sizeof(EAOP2));
     281        if (!rc) {
     282          pfea = &eaop.fpFEA2List->list[0];
     283          value = pfea->szName + pfea->cbName + 1;
     284          value[pfea->cbValue] = 0;
     285          if (*(USHORT *) value == EAT_ASCII)
     286            strncat(longname,
     287                    value + (sizeof(USHORT) * 2),
     288                    CCHMAXPATH - strlen(longname));
     289          longname[CCHMAXPATH - 1] = 0;
     290        }
     291        free(pfealist);
    281292      }
    282293      free(pgealist);
     
    286297}
    287298
    288 BOOL ZapLongName(char *filename)
     299BOOL ZapLongName(PSZ filename)
    289300{
    290301  return WriteLongName(filename, NullStr);
     
    315326    ealen = sizeof(FEALIST) + 10;
    316327  rc = xDosAllocMem((PPVOID) & pfealist,
    317                     ealen + 32L, PAG_COMMIT | PAG_READ | PAG_WRITE,
    318                     pszSrcFile, __LINE__);
     328                    ealen + 32L, PAG_COMMIT | PAG_READ | PAG_WRITE,
     329                    pszSrcFile, __LINE__);
    319330  if (rc)
    320331    Dos_Error(MB_CANCEL, rc, HWND_DESKTOP, pszSrcFile, __LINE__,
    321               GetPString(IDS_OUTOFMEMORY));
     332              GetPString(IDS_OUTOFMEMORY));
    322333  else {
    323334    memset(pfealist, 0, ealen + 1);
     
    343354    DosError(FERR_DISABLEHARDERR);
    344355    rc = xDosSetPathInfo(filename, FIL_QUERYEASIZE,
    345                         &eaop, sizeof(eaop), DSPI_WRTTHRU);
     356                        &eaop, sizeof(eaop), DSPI_WRTTHRU);
    346357    DosFreeMem(pfealist);
    347358    if (rc)
     
    355366  BOOL ret = FALSE;
    356367
    357   /* NOTE: newname should be CCHMAXPATH chars long! */
     368  // NOTE: newname should be CCHMAXPATH chars long!
    358369
    359370  if (strchr(newname, '*') || strchr(newname, '?')) {
     
    367378      p = strrchr(oldname, '\\');
    368379      if (p && *(p + 1)) {
    369         strcpy(srce, p + 1);
    370         DosError(FERR_DISABLEHARDERR);
    371         if (!DosEditName(1L, srce, dest, (PBYTE)result, (ULONG)sizeof(result))) {
    372           p = strrchr(newname, '\\');
    373           p++;
    374           strcpy(p, result);
    375           ret = TRUE;
    376         }
     380        strcpy(srce, p + 1);
     381        DosError(FERR_DISABLEHARDERR);
     382        if (!DosEditName(1L, srce, dest, (PBYTE)result, (ULONG)sizeof(result))) {
     383          p = strrchr(newname, '\\');
     384          p++;
     385          strcpy(p, result);
     386          ret = TRUE;
     387        }
    377388      }
    378389    }
     
    381392}
    382393
     394/** Copy/move file
     395 * @param type is copy/move type
     396 * @param oldname is fully qualified source file name
     397 * @param newname is fully qualified destination file name
     398 * @return
     399 *   0:  success
     400 *  -1:  bad parameter(s)
     401 *  -2:  source does not exist
     402 *  -3:  bad copy/move type
     403 *   anything else: API return
     404 */
     405
    383406APIRET docopyf(INT type, CHAR *oldname, CHAR *newname)
    384407{
    385   /*
    386    * returns:
    387    *   0:  success
    388    *  -1:  bad string parameter(s)
    389    *  -2:  source didn't exist
    390    *  -3:  bad type
    391    *   anything else: API return
    392    */
    393 
    394408  CHAR longname[CCHMAXPATH], shortname[CCHMAXPATH];
    395409  CHAR olddisk, newdisk, dir[CCHMAXPATH], *p, *pp;
     
    400414  *shortname = *dir = 0;
    401415
    402   if (!oldname || !*oldname || !*newname)   /* bad string args */
    403     return (APIRET) - 1;
     416  if (!oldname || !*oldname || !*newname)
     417    return (APIRET)-1;                  // bad args
    404418
    405419  DosError(FERR_DISABLEHARDERR);
    406420  if (DosQueryPathInfo(oldname, FIL_STANDARDL, &st, sizeof(FILESTATUS3L)))
    407     return (APIRET) - 2;                /* no source */
     421    return (APIRET)-2;                  // can not access source
    408422
    409423  AdjustWildcardName(oldname, newname);
    410424  MakeFullName(oldname);
    411425  MakeFullName(newname);
    412   olddisk = toupper(*oldname);          /* source drive */
    413   newdisk = toupper(*newname);      /* destination drive */
     426  olddisk = toupper(*oldname);          // source drive
     427  newdisk = toupper(*newname);          // destination drive
    414428  if (!(driveflags[toupper(*oldname) - 'A'] & DRIVE_NOLONGNAMES))
    415429    *longname = 0;
     
    419433      p = RootName(longname);
    420434      if (p != longname)
    421         memmove(longname, p, strlen(p) + 1);
    422     }
    423   }
    424   /* If root name changed make sure longname EA goes away */
     435        memmove(longname, p, strlen(p) + 1);
     436    }
     437  }
     438  // If root name changed make sure longname EA goes away
    425439  if (*longname) {
    426440    p = RootName(oldname);
     
    441455      hobjsrc = WinQueryObject(oldname);
    442456      if (hobjsrc) {
    443         strcpy(dir, newname);
    444         p = strrchr(dir, '\\');
    445         if (p < dir + 3)
    446           p++;
    447         *p = 0;
    448         ret = ERROR_PATH_NOT_FOUND;
    449         hobjdest = WinQueryObject(dir);
    450         if (hobjdest) {
    451           ret = ERROR_GEN_FAILURE;
    452           hobjsrc = WinMoveObject(hobjsrc, hobjdest, 0);
    453           if (hobjsrc)
    454             ret = 0;
    455         }
     457        strcpy(dir, newname);
     458        p = strrchr(dir, '\\');
     459        if (p < dir + 3)
     460          p++;
     461        *p = 0;
     462        ret = ERROR_PATH_NOT_FOUND;
     463        hobjdest = WinQueryObject(dir);
     464        if (hobjdest) {
     465          ret = ERROR_GEN_FAILURE;
     466          hobjsrc = WinMoveObject(hobjsrc, hobjdest, 0);
     467          if (hobjsrc)
     468            ret = 0;
     469        }
    456470      }
    457471    }
     
    466480      hobjsrc = WinQueryObject(oldname);
    467481      if (hobjsrc) {
    468         strcpy(dir, newname);
    469         p = strrchr(dir, '\\');
    470         if (p < dir + 3)
    471           p++;
    472         *p = 0;
    473         ret = ERROR_PATH_NOT_FOUND;
    474         hobjdest = WinQueryObject(dir);
    475         if (hobjdest) {
    476           ret = ERROR_GEN_FAILURE;
    477           hobjsrc = WinCopyObject(hobjsrc, hobjdest, 0);
    478           if (hobjsrc)
    479             ret = 0;
    480         }
     482        strcpy(dir, newname);
     483        p = strrchr(dir, '\\');
     484        if (p < dir + 3)
     485          p++;
     486        *p = 0;
     487        ret = ERROR_PATH_NOT_FOUND;
     488        hobjdest = WinQueryObject(dir);
     489        if (hobjdest) {
     490          ret = ERROR_GEN_FAILURE;
     491          hobjsrc = WinCopyObject(hobjsrc, hobjdest, 0);
     492          if (hobjsrc)
     493            ret = 0;
     494        }
    481495      }
    482496    }
     
    485499  case MOVE:
    486500    *dir = 0;
    487     if (olddisk == newdisk) {           /* same drive */
    488       /* make temporary copy in case move fails */
     501    if (olddisk == newdisk) {
     502      // Moving to same drive
     503      // make temporary copy in case move fails
    489504      if (IsFile(newname) != -1 && stricmp(oldname, newname)) {
    490         strcpy(dir, newname);
    491         AddBackslashToPath(dir);
    492         //p = strrchr(dir, '\\');
    493         //if (p)
    494         //  *p = 0;
    495         //strcat(dir, "\\");
    496         MakeTempName(dir, NULL, 0);
    497         if (DosMove(newname, dir))
    498           *dir = 0;
     505        // 19 Oct 09 SHL correct regression
     506        strcpy(dir, newname);
     507        p = strrchr(dir, '\\');
     508        if (p)
     509          *p = 0;
     510        AddBackslashToPath(dir);
     511        MakeTempName(dir, NULL, 0);
     512        if (DosMove(newname, dir))
     513          *dir = 0;                     // Avoid trying to restore bad copy
    499514      }
    500515      DosError(FERR_DISABLEHARDERR);
    501       ret = DosMove(oldname, newname);      /* move it */
    502       if (ret && *dir) {                /* failed -- clean up */
    503         DosError(FERR_DISABLEHARDERR);
    504         if (!DosMove(dir, newname))
    505           Broadcast((HAB) 0, hwndMain, UM_UPDATERECORD, MPFROMP(dir), MPVOID);
     516      ret = DosMove(oldname, newname);  // move it
     517      if (ret && *dir) {                // failed -- clean up
     518        DosError(FERR_DISABLEHARDERR);
     519        if (!DosMove(dir, newname))
     520          Broadcast((HAB) 0, hwndMain, UM_UPDATERECORD, MPFROMP(dir), MPVOID);
    506521      }
    507522      else if (!ret && *dir) {
    508         if (!IsFile(dir)) {
    509           if (!strchr(dir, '?') && !strchr(dir, '*'))
    510             wipeallf("%s\\*", dir);
    511           DosError(FERR_DISABLEHARDERR);
    512           if (DosDeleteDir(dir)) {
    513             make_deleteable(dir);
    514             DosDeleteDir(dir);
    515           }
    516         }
    517         else if (IsFile(dir) > 0) {
    518           DosError(FERR_DISABLEHARDERR);
    519           if (DosForceDelete(dir)) {
    520             make_deleteable(dir);
    521             DosForceDelete(dir);
    522           }
    523           if (zaplong) {
    524             ret = ZapLongName(dir);
    525           }
    526           Broadcast((HAB) 0, hwndMain, UM_UPDATERECORD, MPFROMP(dir), MPVOID);
    527         }
    528       }
    529     }
    530     else {                              /* different drives */
     523        if (!IsFile(dir)) {
     524          if (!strchr(dir, '?') && !strchr(dir, '*'))
     525            wipeallf("%s\\*", dir);
     526          DosError(FERR_DISABLEHARDERR);
     527          if (DosDeleteDir(dir)) {
     528            make_deleteable(dir);
     529            DosDeleteDir(dir);
     530          }
     531        }
     532        else if (IsFile(dir) > 0) {
     533          DosError(FERR_DISABLEHARDERR);
     534          if (DosForceDelete(dir)) {
     535            make_deleteable(dir);
     536            DosForceDelete(dir);
     537          }
     538          if (zaplong) {
     539            ret = ZapLongName(dir);
     540          }
     541          Broadcast((HAB) 0, hwndMain, UM_UPDATERECORD, MPFROMP(dir), MPVOID);
     542        }
     543      }
     544    }
     545    else {
     546      // Moving to different drive
    531547      DosError(FERR_DISABLEHARDERR);
    532       ret = DosCopy(oldname, newname, DCPY_EXISTING);       /* <=-NOTE! */
     548      ret = DosCopy(oldname, newname, DCPY_EXISTING);   // <=-NOTE!
    533549      if (ret == ERROR_DISK_CHANGE) {
    534         DosError(FERR_ENABLEHARDERR);
    535         ret = DosCopy(oldname, newname, DCPY_EXISTING);
    536         diskchange = TRUE;
     550        DosError(FERR_ENABLEHARDERR);
     551        ret = DosCopy(oldname, newname, DCPY_EXISTING);
     552        diskchange = TRUE;
    537553      }
    538554      if (ret == ERROR_INVALID_NAME || ret == ERROR_FILENAME_EXCED_RANGE) {
    539         if (TruncName(newname, shortname)) {        /* make 8.3 filename */
    540           DosError(FERR_DISABLEHARDERR);
    541           ret = DosCopy(oldname, shortname, DCPY_EXISTING);
    542           if (!ret) {                   /* success -- write longname ea */
    543             WriteLongName(shortname, newname);
    544             strcpy(newname, shortname);
    545             /* broadcast fixup msg to windows */
    546             Broadcast((HAB) 0,
    547                       hwndMain, UM_UPDATERECORD, MPFROMP(shortname), MPVOID);
    548           }
    549         }
     555        if (TruncName(newname, shortname)) {
     556          // make 8.3 filename
     557          DosError(FERR_DISABLEHARDERR);
     558          ret = DosCopy(oldname, shortname, DCPY_EXISTING);
     559          if (!ret) {
     560            // success -- write longname ea
     561            WriteLongName(shortname, newname);
     562            strcpy(newname, shortname);
     563            // broadcast fixup msg to windows
     564            Broadcast((HAB) 0,
     565                      hwndMain, UM_UPDATERECORD, MPFROMP(shortname), MPVOID);
     566          }
     567        }
    550568      }
    551569      else if (!ret && *longname) {
    552570
    553         CHAR fixname[CCHMAXPATH];
    554 
    555         strcpy(fixname, newname);
    556         p = strrchr(fixname, '\\');
    557         if (p) {
    558           p++;
    559           *p = 0;
    560         }
    561         strcat(fixname, longname);
    562         DosError(FERR_DISABLEHARDERR);
    563         DosMove(newname, fixname);
    564         strcpy(newname, fixname);
    565         if (zaplong)
    566           ZapLongName(fixname);
    567         Broadcast((HAB) 0,
    568                   hwndMain, UM_UPDATERECORD, MPFROMP(fixname), MPVOID);
    569       }
    570       if (!ret) {                       /* double-check success */
    571         DosError(FERR_DISABLEHARDERR);
    572         rc = DosQueryPathInfo(newname,
    573                               FIL_STANDARDL, &st2, sizeof(FILESTATUS3L));
    574         if (rc == ERROR_DISK_CHANGE) {
    575           DosError(FERR_ENABLEHARDERR);
    576           rc = DosQueryPathInfo(newname,
    577                                 FIL_STANDARDL, &st2, sizeof(FILESTATUS3L));
    578         }
    579         if (!rc && st2.cbFile == st.cbFile) {   /* seems to have worked... */
    580           DosError(FERR_DISABLEHARDERR);
    581           if (diskchange) {
    582             DosError(FERR_ENABLEHARDERR);
    583             DosQueryPathInfo(oldname, FIL_STANDARDL, &dummy, sizeof(FILESTATUS3L));     /* force disk change */
    584           }
    585           if (!(st2.attrFile & FILE_DIRECTORY)) /* erase file */
    586             unlinkf(oldname);
    587           else {                        /* remove directory */
    588             wipeallf("%s\\*", oldname);
    589             DosError(FERR_DISABLEHARDERR);
    590             if (DosDeleteDir(oldname)) {
    591               make_deleteable(oldname);
    592               DosDeleteDir(oldname);
    593             }
    594           }
    595         }
     571        CHAR fixname[CCHMAXPATH];
     572
     573        strcpy(fixname, newname);
     574        p = strrchr(fixname, '\\');
     575        if (p) {
     576          p++;
     577          *p = 0;
     578        }
     579        strcat(fixname, longname);
     580        DosError(FERR_DISABLEHARDERR);
     581        DosMove(newname, fixname);
     582        strcpy(newname, fixname);
     583        if (zaplong)
     584          ZapLongName(fixname);
     585        Broadcast((HAB) 0,
     586                  hwndMain, UM_UPDATERECORD, MPFROMP(fixname), MPVOID);
     587      }
     588      if (!ret) {
     589        // double-check success
     590        DosError(FERR_DISABLEHARDERR);
     591        rc = DosQueryPathInfo(newname,
     592                              FIL_STANDARDL, &st2, sizeof(FILESTATUS3L));
     593        if (rc == ERROR_DISK_CHANGE) {
     594          DosError(FERR_ENABLEHARDERR);
     595          rc = DosQueryPathInfo(newname,
     596                                FIL_STANDARDL, &st2, sizeof(FILESTATUS3L));
     597        }
     598        if (!rc && st2.cbFile == st.cbFile) {
     599          // seems to have worked...
     600          DosError(FERR_DISABLEHARDERR);
     601          if (diskchange) {
     602            DosError(FERR_ENABLEHARDERR);
     603            DosQueryPathInfo(oldname, FIL_STANDARDL, &dummy, sizeof(FILESTATUS3L));     // force disk change
     604          }
     605          if (!(st2.attrFile & FILE_DIRECTORY))
     606            unlinkf(oldname);           // erase file
     607          else {
     608            // remove directory
     609            wipeallf("%s\\*", oldname);
     610            DosError(FERR_DISABLEHARDERR);
     611            if (DosDeleteDir(oldname)) {
     612              make_deleteable(oldname);
     613              DosDeleteDir(oldname);
     614            }
     615          }
     616        }
    596617      }
    597618    }
     
    600621  case COPY:
    601622    DosError(FERR_DISABLEHARDERR);
    602     ret = DosCopy(oldname, newname, DCPY_EXISTING); /* <=-NOTE! */
     623    ret = DosCopy(oldname, newname, DCPY_EXISTING);     // <=-NOTE!
    603624    if (ret == ERROR_DISK_CHANGE) {
    604625      DosError(FERR_ENABLEHARDERR);
     
    608629    if (ret == ERROR_INVALID_NAME || ret == ERROR_FILENAME_EXCED_RANGE) {
    609630      if (TruncName(newname, shortname)) {
    610         DosError((diskchange) ? FERR_ENABLEHARDERR : FERR_DISABLEHARDERR);
    611         ret = DosCopy(oldname, shortname, DCPY_EXISTING);
    612         if (!ret) {
    613           WriteLongName(shortname, newname);
    614           strcpy(newname, shortname);
    615           Broadcast((HAB) 0,
    616                     hwndMain, UM_UPDATERECORD, MPFROMP(shortname), MPVOID);
    617         }
     631        DosError((diskchange) ? FERR_ENABLEHARDERR : FERR_DISABLEHARDERR);
     632        ret = DosCopy(oldname, shortname, DCPY_EXISTING);
     633        if (!ret) {
     634          WriteLongName(shortname, newname);
     635          strcpy(newname, shortname);
     636          Broadcast((HAB) 0,
     637                    hwndMain, UM_UPDATERECORD, MPFROMP(shortname), MPVOID);
     638        }
    618639      }
    619640    }
     
    625646      p = strrchr(fixname, '\\');
    626647      if (p) {
    627         p++;
    628         *p = 0;
     648        p++;
     649        *p = 0;
    629650      }
    630651      strcat(fixname, longname);
     
    632653      DosMove(newname, fixname);
    633654      if (zaplong)
    634         ZapLongName(fixname);
     655        ZapLongName(fixname);
    635656      Broadcast((HAB) 0, hwndMain, UM_UPDATERECORD, MPFROMP(fixname), MPVOID);
    636657    }
    637658    return ret;
    638659
    639   default:                              /* shouldn't happen */
     660  default:
     661    // shouldn't happen
    640662    Runtime_Error(pszSrcFile, __LINE__, "bad case %u", type);
    641663    break;
    642   }
    643   return (APIRET) - 3;                  /* bad type */
     664  } // switch type
     665  Runtime_Error(pszSrcFile, __LINE__, "copy/move type %u unexpected", type);
     666  return (APIRET)-3;                    // bad copy/move type
    644667}
    645668
     
    659682}
    660683
     684/**
     685 * unlink everything from directory on down...
     686 */
     687
    661688INT wipeallf(CHAR *string, ...)
    662689{
    663   /* unlink everything from directory on down... */
    664 
    665690  FILEFINDBUF3 *f;
    666691  HDIR search_handle;
     
    687712    return -1;
    688713
    689   {                                     /* safety net -- disallow deleting a root dir or partial name */
     714  {
     715    // safety net -- disallow deleting a root dir or partial name
    690716    CHAR temp;
    691 
    692717    p = strrchr(str, '\\');
    693718    if (p) {
     
    696721      *p = 0;
    697722      if (IsRoot(str) || !IsFullName(str)) {
    698         /* under no circumstances! */
    699         Runtime_Error(pszSrcFile, __LINE__, "bad name %s", str);
    700         free(str);
    701         return -1;
     723        // under no circumstances!
     724        Runtime_Error(pszSrcFile, __LINE__, "bad name %s", str);
     725        free(str);
     726        return -1;
    702727      }
    703728      *p = temp;
     
    706731
    707732  p = s;
    708   p = strrchr(s, '\\');                 /* strip s to just path */
     733  p = strrchr(s, '\\');                 // strip s to just path
    709734  if (!p)
    710735    p = strrchr(s, ':');
     
    734759  DosError(FERR_DISABLEHARDERR);
    735760  if (!DosFindFirst(str, &search_handle, FILE_NORMAL | FILE_DIRECTORY |
    736                      FILE_SYSTEM | FILE_READONLY | FILE_HIDDEN | FILE_ARCHIVED,
    737                      f, sizeof(FILEFINDBUF3), &num_matches, FIL_STANDARD)) {
     761                     FILE_SYSTEM | FILE_READONLY | FILE_HIDDEN | FILE_ARCHIVED,
     762                     f, sizeof(FILEFINDBUF3), &num_matches, FIL_STANDARD)) {
    738763
    739764    strcpy(ss, s);
     
    743768      strcpy(p, f->achName);
    744769      if (f->attrFile & FILE_DIRECTORY) {
    745         if (strcmp(f->achName, ".") && strcmp(f->achName, "..")) {
    746           wipeallf("%s/%s", ss, mask);  /* recurse to wipe files */
    747           DosError(FERR_DISABLEHARDERR);
    748           if (DosDeleteDir(ss)) {       /* remove directory */
    749             make_deleteable(ss);
    750             DosError(FERR_DISABLEHARDERR);
    751             DosDeleteDir(ss);
    752           }
    753         }
     770        if (strcmp(f->achName, ".") && strcmp(f->achName, "..")) {
     771          wipeallf("%s/%s", ss, mask);  // recurse to wipe files
     772          DosError(FERR_DISABLEHARDERR);
     773          // remove directory
     774          if (DosDeleteDir(ss)) {
     775            make_deleteable(ss);        // Try harder
     776            DosError(FERR_DISABLEHARDERR);
     777            DosDeleteDir(ss);
     778          }
     779        }
    754780      }
    755781      else {
    756         DosError(FERR_DISABLEHARDERR);
    757         if (DosForceDelete(ss)) {
    758           make_deleteable(ss);
    759           DosError(FERR_DISABLEHARDERR);
    760           rc = (INT) DosForceDelete(ss);
    761           if (rc)
    762             return rc;
    763         }
     782        DosError(FERR_DISABLEHARDERR);
     783        if (DosForceDelete(ss)) {
     784          make_deleteable(ss);
     785          DosError(FERR_DISABLEHARDERR);
     786          rc = (INT) DosForceDelete(ss);
     787          if (rc)
     788            return rc;
     789        }
    764790      }
    765791      num_matches = 1;
    766792      DosError(FERR_DISABLEHARDERR);
    767793    } while (!DosFindNext(search_handle, f, sizeof(FILEFINDBUF3),
    768                           &num_matches));
     794                          &num_matches));
    769795    DosFindClose(search_handle);
    770796  }
     
    776802}
    777803
    778 #if 0   // JBS  11 Sep 08
     804#if 0 // JBS 11 Sep 08 fixme to be gone
    779805INT unlink_allf(CHAR * string, ...)
    780806{
    781   /* wildcard delete */
    782 
     807  // wildcard delete
    783808  FILEFINDBUF3 *f;
    784809  HDIR search_handle;
     
    787812  CHAR s[CCHMAXPATH];
    788813  va_list ap;
    789 
    790814  va_start(ap, string);
    791815  vsprintf(s, string, ap);
     
    805829
    806830  p = s;
    807   p = strrchr(s, '\\');                 /* strip s to just path */
     831  p = strrchr(s, '\\');                 // strip s to just path
    808832  if (!p)
    809833    p = strrchr(s, ':');
     
    829853  DosError(FERR_DISABLEHARDERR);
    830854  if (!DosFindFirst(str, &search_handle, FILE_NORMAL, f,
    831                     sizeof(FILEFINDBUF3), &num_matches, FIL_STANDARD)) {
     855                    sizeof(FILEFINDBUF3), &num_matches, FIL_STANDARD)) {
    832856
    833857    strcpy(ss, s);
     
    840864      DosError(FERR_DISABLEHARDERR);
    841865    } while (!DosFindNext(search_handle, f, sizeof(FILEFINDBUF3),
    842                           &num_matches));
     866                          &num_matches));
    843867    DosFindClose(search_handle);
    844868  }
     
    858882INT unlinkf(CHAR *string)
    859883{
    860 
    861884  if (!strstr(string, ArcTempRoot)) {
    862885    DosError(FERR_DISABLEHARDERR);
Note: See TracChangeset for help on using the changeset viewer.