Ignore:
Timestamp:
Feb 27, 2003, 12:27:11 PM (22 years ago)
Author:
sandervl
Message:

AH: MoveFile: detect if source and target file names are on a different drive and use DosCopy/DosDelete instead of DosMove in this case

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kernel32/oslibdos.cpp

    r9815 r9861  
    1 /* $Id: oslibdos.cpp,v 1.115 2003-02-17 11:31:43 sandervl Exp $ */
     1/* $Id: oslibdos.cpp,v 1.116 2003-02-27 11:27:11 sandervl Exp $ */
    22/*
    33 * Wrappers for OS/2 Dos* API
     
    519519  CharToOemA(lpszNewFile, lOemNewFile);
    520520
    521   rc = DosMove((PSZ)lOemOldFile, (PSZ)lOemNewFile);
    522   SetLastError(error2WinError(rc));
     521  // we need to know the current drive for relative paths
     522  ULONG diskNum, logicalBitmap;
     523  DosQueryCurrentDisk(&diskNum, &logicalBitmap);
     524  char currentDrive = 'A' + diskNum - 1;
     525
     526  // first determine whether source and target paths are absolute
     527  // (i.e. contain a drive letter)
     528  BOOL sourcePathAbsolute = FALSE;
     529  char sourceDrive = currentDrive;
     530  if ((strlen(lOemOldFile) > 2) && (lOemOldFile[1] == ':'))
     531  {
     532      sourcePathAbsolute = TRUE;
     533      sourceDrive = toupper(lOemOldFile[1]);
     534  }
     535  BOOL targetPathAbsolute = FALSE;
     536  char targetDrive = currentDrive;
     537  if ((strlen(lOemNewFile) > 2) && (lOemNewFile[1] == ':'))
     538  {
     539      targetPathAbsolute = TRUE;
     540      targetDrive = toupper(lOemNewFile[1]);
     541  }
     542
     543  // if the source and target drives are different, we have to do take
     544  // the copy and delete path
     545  if (sourceDrive != targetDrive)
     546  {
     547      dprintf(("OSLibDosMoveFile - different drives, doing the copy/delete approach (WARNING: non atomic file system operation!)"));
     548      // @@@AH TODO: this is not atomic. Maybe it is on Windows - we have to check this
     549      rc = DosCopy((PSZ)lOemOldFile, (PSZ)lOemNewFile, 0);
     550      if (rc == NO_ERROR)
     551      {
     552          rc = DosDelete(lOemOldFile);
     553      }
     554      SetLastError(error2WinError(rc));
     555  } else
     556  {
     557      // atomic DosMove will do fine
     558      rc = DosMove((PSZ)lOemOldFile, (PSZ)lOemNewFile);
     559      SetLastError(error2WinError(rc));
     560  }     
    523561  return (rc == NO_ERROR);
    524562}
     
    14731511DWORD OSLibDosDupHandle(DWORD hFile, DWORD *hNew)
    14741512{
    1475    *hNew = -1;
    1476    return DosDupHandle(hFile, hNew);
     1513   DWORD dwNewHandle = -1, ret;
     1514
     1515   //Use the stack for storing the new handle; DosDupHandle doesn't like high
     1516   //addresses
     1517   ret = DosDupHandle(hFile, &dwNewHandle);
     1518   *hNew = dwNewHandle;
     1519   return ret;
    14771520}
    14781521//******************************************************************************
Note: See TracChangeset for help on using the changeset viewer.