From 5f6c317492e25b130cfee586c287a33c008c30a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20Czerpak?= Date: Wed, 5 Mar 2014 11:59:16 +0100 Subject: [PATCH] 2014-03-05 11:59 UTC+0100 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) * src/debug/dbgentry.c ! added additional protection against recursive debugger activation. It should fix problem reported by Rafa. * src/rtl/fssize.c * use explicit open attributes. * src/rtl/copyfile.c ! reset error object between different RTE calls in __copyFile() ! copy file attributes only on *nix platforms. In Cl*pper __copyFile() does not copy attributes so maybe also in *nixes we should make the same. * contrib/xhb/xhbcopyf.c * changed hb_fs*() API to hb_file*() API. --- ChangeLog.txt | 17 +++++ contrib/xhb/xhbcopyf.c | 150 ++++++++++++++++++++++++++--------------- src/debug/dbgentry.c | 6 +- src/rtl/copyfile.c | 35 +++++++--- src/rtl/fssize.c | 2 +- 5 files changed, 142 insertions(+), 68 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 663a6bd1e9..2e87b27b6c 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -10,6 +10,23 @@ * Change, ! Fix, % Optimization, + Addition, - Removal, ; Comment */ +2014-03-05 11:59 UTC+0100 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) + * src/debug/dbgentry.c + ! added additional protection against recursive debugger activation. + It should fix problem reported by Rafa. + + * src/rtl/fssize.c + * use explicit open attributes. + + * src/rtl/copyfile.c + ! reset error object between different RTE calls in __copyFile() + ! copy file attributes only on *nix platforms. + In Cl*pper __copyFile() does not copy attributes so maybe also + in *nixes we should make the same. + + * contrib/xhb/xhbcopyf.c + * changed hb_fs*() API to hb_file*() API. + 2014-03-04 19:12 UTC+0100 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) * contrib/xhb/hbserv.c * pacified CLANG warning reported by FranĨek diff --git a/contrib/xhb/xhbcopyf.c b/contrib/xhb/xhbcopyf.c index 42885ee569..0553aada0f 100644 --- a/contrib/xhb/xhbcopyf.c +++ b/contrib/xhb/xhbcopyf.c @@ -59,81 +59,116 @@ #define BUFFER_SIZE 8192 -static HB_BOOL hb_copyfile( const char * szSource, const char * szDest, PHB_ITEM pBlock ) +static HB_BOOL hb_copyfile( const char * pszSource, const char * pszDest, PHB_ITEM pBlock ) { - HB_BOOL bRetVal = HB_FALSE; - HB_FHANDLE fhndSource; + HB_BOOL bRetVal = HB_FALSE; + PHB_FILE pSource; + PHB_ITEM pError = NULL; - HB_TRACE( HB_TR_DEBUG, ( "hb_copyfile(%s, %s)", szSource, szDest ) ); + HB_TRACE( HB_TR_DEBUG, ( "hb_copyfile(%s, %s, %p)", pszSource, pszDest, pBlock ) ); - while( ( fhndSource = hb_spOpen( szSource, FO_READ | FO_SHARED | FO_PRIVATE ) ) == FS_ERROR ) + do { - HB_USHORT uiAction = hb_errRT_BASE_Ext1( EG_OPEN, 2012, NULL, szSource, hb_fsError(), EF_CANDEFAULT | EF_CANRETRY, 0 ); - - if( uiAction != E_RETRY ) - break; - } - - if( fhndSource != FS_ERROR ) - { - HB_FHANDLE fhndDest; - - while( ( fhndDest = hb_spCreate( szDest, FC_NORMAL ) ) == FS_ERROR ) + pSource = hb_fileExtOpen( pszSource, NULL, + FO_READ | FO_SHARED | FO_PRIVATE | + FXO_DEFAULTS | FXO_SHARELOCK, + NULL, pError ); + if( pSource == NULL ) { - HB_USHORT uiAction = hb_errRT_BASE_Ext1( EG_CREATE, 2012, NULL, szDest, hb_fsError(), EF_CANDEFAULT | EF_CANRETRY, 0 ); - - if( uiAction != E_RETRY ) + pError = hb_errRT_FileError( pError, NULL, EG_OPEN, 2012, pszSource ); + if( hb_errLaunch( pError ) != E_RETRY ) break; } + } + while( pSource == NULL ); - if( fhndDest != FS_ERROR ) + if( pError ) + { + hb_itemRelease( pError ); + pError = NULL; + } + + if( pSource != NULL ) + { + PHB_FILE pDest; + + do { -#if defined( HB_OS_UNIX ) - struct stat struFileInfo; - int iSuccess = fstat( fhndSource, &struFileInfo ); -#endif - HB_BYTE * buffer = ( HB_BYTE * ) hb_xgrab( BUFFER_SIZE ); - HB_USHORT usRead; - - bRetVal = HB_TRUE; - - if( hb_itemType( pBlock ) != HB_IT_BLOCK ) - pBlock = NULL; - - while( ( usRead = hb_fsRead( fhndSource, buffer, BUFFER_SIZE ) ) != 0 ) + pDest = hb_fileExtOpen( pszDest, NULL, + FO_READWRITE | FO_EXCLUSIVE | FO_PRIVATE | + FXO_TRUNCATE | FXO_DEFAULTS | FXO_SHARELOCK, + NULL, pError ); + if( pDest == NULL ) { - while( hb_fsWrite( fhndDest, buffer, usRead ) != usRead ) - { - HB_USHORT uiAction = hb_errRT_BASE_Ext1( EG_WRITE, 2016, NULL, szDest, hb_fsError(), EF_CANDEFAULT | EF_CANRETRY, 0 ); + pError = hb_errRT_FileError( pError, NULL, EG_CREATE, 2012, pszDest ); + if( hb_errLaunch( pError ) != E_RETRY ) + break; + } + } + while( pDest == NULL ); - if( uiAction != E_RETRY ) + if( pError ) + { + hb_itemRelease( pError ); + pError = NULL; + } + + if( pDest != NULL ) + { + PHB_ITEM pCount = NULL; + HB_UCHAR * buffer; + HB_SIZE nRead; + + buffer = ( HB_UCHAR * ) hb_xgrab( BUFFER_SIZE ); + bRetVal = HB_TRUE; + if( pBlock && HB_IS_EVALITEM( pBlock ) ) + pCount = hb_itemNew( NULL ); + + while( ( nRead = hb_fileRead( pSource, buffer, BUFFER_SIZE, -1 ) ) != 0 ) + { + HB_SIZE nWritten = 0; + + while( nWritten < nRead ) + { + nWritten += hb_fileWrite( pDest, buffer + nWritten, nRead - nWritten, -1 ); + if( nWritten < nRead ) { - bRetVal = HB_FALSE; - break; + pError = hb_errRT_FileError( pError, NULL, EG_WRITE, 2016, pszDest ); + if( hb_errLaunch( pError ) != E_RETRY ) + { + bRetVal = HB_FALSE; + break; + } } } - if( pBlock ) - { - PHB_ITEM pCnt = hb_itemPutNL( NULL, usRead ); - - hb_vmEvalBlockV( pBlock, 1, pCnt ); - - hb_itemRelease( pCnt ); - } + if( pCount ) + hb_vmEvalBlockV( pBlock, 1, hb_itemPutNInt( pCount, nRead ) ); } + if( pError ) + hb_itemRelease( pError ); + + if( pCount ) + hb_itemRelease( pCount ); + hb_xfree( buffer ); -#if defined( HB_OS_UNIX ) - if( iSuccess == 0 ) - fchmod( fhndDest, struFileInfo.st_mode ); -#endif - - hb_fsClose( fhndDest ); + hb_fileClose( pDest ); } - hb_fsClose( fhndSource ); + hb_fileClose( pSource ); + + if( bRetVal ) + { + long lJulian, lMillisec; + HB_FATTR ulAttr; + + if( hb_fileAttrGet( pszSource, &ulAttr ) ) + hb_fileAttrSet( pszDest, ulAttr ); + if( hb_fileTimeGet( pszSource, &lJulian, &lMillisec ) ) + hb_fileTimeSet( pszDest, lJulian, lMillisec ); + } } return bRetVal; @@ -143,9 +178,12 @@ static HB_BOOL hb_copyfile( const char * szSource, const char * szDest, PHB_ITEM HB_FUNC( XHB_COPYFILE ) { - if( HB_ISCHAR( 1 ) && HB_ISCHAR( 2 ) ) + const char * szSource = hb_parc( 1 ); + const char * szDest = hb_parc( 2 ); + + if( szSource && szDest ) { - if( ! hb_copyfile( hb_parc( 1 ), hb_parc( 2 ), hb_param( 3, HB_IT_BLOCK ) ) ) + if( ! hb_copyfile( szSource, szDest, hb_param( 3, HB_IT_EVALITEM ) ) ) hb_retl( HB_FALSE ); } else diff --git a/src/debug/dbgentry.c b/src/debug/dbgentry.c index bd37f43423..f255a4d1fd 100644 --- a/src/debug/dbgentry.c +++ b/src/debug/dbgentry.c @@ -219,6 +219,7 @@ static void hb_dbgActivate( HB_DEBUGINFO * info ) PHB_ITEM aCallStack = hb_itemArrayNew( info->nCallStackLen ); PHB_ITEM aModules; PHB_ITEM aBreak; + HB_BOOL bInside = info->bInside; int i; for( i = 0; i < info->nCallStackLen; i++ ) @@ -260,7 +261,9 @@ static void hb_dbgActivate( HB_DEBUGINFO * info ) hb_itemRelease( aModules ); hb_itemRelease( aBreak ); + info->bInside = HB_TRUE; hb_vmDo( 6 ); + info->bInside = bInside; } } @@ -962,13 +965,14 @@ static PHB_ITEM hb_dbgEval( HB_DEBUGINFO * info, HB_WATCHPOINT * watch ) { PHB_ITEM aVars = hb_dbgEvalResolve( info, watch ); PHB_ITEM aNewVars = hb_itemArrayNew( watch->nVars ); + HB_BOOL bInside = info->bInside; int i; hb_arrayCopy( aVars, aNewVars, NULL, NULL, NULL ); info->bInside = HB_TRUE; xResult = hb_itemDo( watch->pBlock, 1, aNewVars ); - info->bInside = HB_FALSE; + info->bInside = bInside; for( i = 0; i < watch->nVars; i++ ) { diff --git a/src/rtl/copyfile.c b/src/rtl/copyfile.c index ac3d5fe12f..305b296dbb 100644 --- a/src/rtl/copyfile.c +++ b/src/rtl/copyfile.c @@ -85,6 +85,12 @@ static HB_BOOL hb_copyfile( const char * pszSource, const char * pszDest ) } while( pSource == NULL ); + if( pError ) + { + hb_itemRelease( pError ); + pError = NULL; + } + if( pSource != NULL ) { PHB_FILE pDest; @@ -104,6 +110,12 @@ static HB_BOOL hb_copyfile( const char * pszSource, const char * pszDest ) } while( pDest == NULL ); + if( pError ) + { + hb_itemRelease( pError ); + pError = NULL; + } + if( pDest != NULL ) { HB_UCHAR * buffer; @@ -131,23 +143,26 @@ static HB_BOOL hb_copyfile( const char * pszSource, const char * pszDest ) } } + if( pError ) + hb_itemRelease( pError ); + hb_xfree( buffer ); - if( bRetVal ) - { - HB_FATTR ulAttr; - - if( hb_fileAttrGet( pszSource, &ulAttr ) ) - hb_fileAttrSet( pszDest, ulAttr ); - } hb_fileClose( pDest ); } hb_fileClose( pSource ); - } - if( pError ) - hb_itemRelease( pError ); +#if defined( HB_OS_UNIX ) + if( bRetVal ) + { + HB_FATTR ulAttr; + + if( hb_fileAttrGet( pszSource, &ulAttr ) ) + hb_fileAttrSet( pszDest, ulAttr ); + } +#endif + } return bRetVal; } diff --git a/src/rtl/fssize.c b/src/rtl/fssize.c index e53eb91c98..0986d22a97 100644 --- a/src/rtl/fssize.c +++ b/src/rtl/fssize.c @@ -119,7 +119,7 @@ HB_FOFFSET hb_fsFSize( const char * pszFileName, HB_BOOL bUseDirEntry ) } else { - HB_FHANDLE hFileHandle = hb_fsOpen( pszFileName, 0 ); + HB_FHANDLE hFileHandle = hb_fsOpen( pszFileName, FO_READ | FO_COMPAT ); if( hFileHandle != FS_ERROR ) {