diff --git a/pal/src/cruntime/filecrt.cpp b/pal/src/cruntime/filecrt.cpp index 790a2626701..9f2bb5d73c1 100644 --- a/pal/src/cruntime/filecrt.cpp +++ b/pal/src/cruntime/filecrt.cpp @@ -332,34 +332,6 @@ PAL_unlink(const char *szPath) } -/*++ -InternalDeleteFile - -Wrapper that does the same thing as unlink, except that -it uses the SYS_Delete system call present on Apple instead of unlink. - -Input parameters: - -szPath = a symbolic link or a hard link to a file - -Return value: - Returns 0 on success and -1 on failure ---*/ -int -CorUnix::InternalDeleteFile( - const char *szPath - ) -{ - int nRet = -1; -#if defined(__APPLE__) && defined(SYS_delete) - nRet = syscall(SYS_delete, szPath); -#else - nRet = unlink(szPath); -#endif // defined(__APPLE__) && defined(SYS_delete) - return nRet; -} - - /*++ PAL_rename diff --git a/pal/src/file/directory.cpp b/pal/src/file/directory.cpp index 784e08c8581..580651bd39f 100644 --- a/pal/src/file/directory.cpp +++ b/pal/src/file/directory.cpp @@ -136,11 +136,6 @@ RemoveDirectoryHelper ( *dwLastError = 0; FILEDosToUnixPathA( lpPathName ); - if ( !FILEGetFileNameFromSymLink(lpPathName)) - { - FILEGetProperNotFoundError( lpPathName, dwLastError ); - goto done; - } if ( rmdir(lpPathName) != 0 ) { @@ -179,7 +174,6 @@ RemoveDirectoryHelper ( bRet = TRUE; } -done: return bRet; } diff --git a/pal/src/file/pal_file.cpp b/pal/src/file/pal_file.cpp index c4157696f42..6eb8bf0b779 100644 --- a/pal/src/file/pal_file.cpp +++ b/pal/src/file/pal_file.cpp @@ -1169,7 +1169,6 @@ DeleteFileA( IN LPCSTR lpFileName) { PAL_ERROR palError = NO_ERROR; - DWORD dwShareMode = SHARE_MODE_NOT_INITALIZED; CPalThread *pThread; int result; BOOL bRet = FALSE; @@ -1196,12 +1195,6 @@ DeleteFileA( lpUnixFileNamePS.CloseBuffer(length); FILEDosToUnixPathA( lpUnixFileName ); - - if ( !FILEGetFileNameFromSymLink(lpUnixFileName)) - { - dwLastError = FILEGetLastErrorFromErrnoAndFilename(lpUnixFileName); - goto done; - } lpFullUnixFileName = reinterpret_cast(InternalMalloc(cchFullUnixFileName)); if ( lpFullUnixFileName == NULL ) @@ -1228,31 +1221,9 @@ DeleteFileA( } } - palError = g_pFileLockManager->GetFileShareModeForFile(lpFullUnixFileName, &dwShareMode); - - // Use unlink if we succesfully found the file to be opened with - // a FILE_SHARE_DELETE mode. - // Note that there is a window here where a race condition can occur: - // the check for the sharing mode and the unlink are two separate actions - // (not a single atomic action). So it's possible that between the check - // happening and the unlink happening, the file may have been closed. If - // it is just closed and not re-opened, no problems. - // If it is closed and re-opened without any sharing, we should be calling - // InternalDelete instead which would have failed. - // Instead, we call unlink which will succeed. + result = unlink( lpFullUnixFileName ); - if (palError == NO_ERROR && - dwShareMode != SHARE_MODE_NOT_INITALIZED && - (dwShareMode & FILE_SHARE_DELETE) != 0) - { - result = unlink( lpFullUnixFileName ); - } - else - { - result = InternalDeleteFile( lpFullUnixFileName ); - } - - if ( result < 0 ) + if (result < 0) { TRACE("unlink returns %d\n", result); dwLastError = FILEGetLastErrorFromErrnoAndFilename(lpFullUnixFileName); @@ -1471,13 +1442,6 @@ MoveFileExA( FILEDosToUnixPathA( dest ); - if ( !FILEGetFileNameFromSymLink(source)) - { - TRACE( "FILEGetFileNameFromSymLink failed\n" ); - dwLastError = FILEGetLastErrorFromErrnoAndFilename(source); - goto done; - } - if ( !(dwFlags & MOVEFILE_REPLACE_EXISTING) ) { #if HAVE_CASE_SENSITIVE_FILESYSTEM @@ -1558,9 +1522,9 @@ MoveFileExA( case ENOENT: { struct stat buf; - if (stat(source, &buf) == -1) + if (lstat(source, &buf) == -1) { - FILEGetProperNotFoundError(dest, &dwLastError); + FILEGetProperNotFoundError(source, &dwLastError); } else { @@ -4951,39 +4915,6 @@ void FILECleanupStdHandles(void) } -/*++ -FILEGetFileNameFromSymLink - -Input parameters: - -source = path to the file on input, path to the file with all - symbolic links traversed on return - -Note: Assumes the maximum size of the source is MAX_LONGPATH - -Return value: - TRUE on success, FALSE on failure ---*/ -BOOL FILEGetFileNameFromSymLink(char *source) -{ - int ret; - char * sLinkData = (char*)InternalMalloc(MAX_LONGPATH); - - do - { - ret = readlink(source, sLinkData, MAX_LONGPATH); - if (ret>0) - { - sLinkData[ret] = '\0'; - strcpy_s(source, sizeof(char)*(MAX_LONGPATH), sLinkData); - } - } while (ret > 0); - - InternalFree(sLinkData); - return (errno == EINVAL); -} - - /*++ Function: GetFileInformationByHandle diff --git a/pal/src/include/pal/file.h b/pal/src/include/pal/file.h index caf982b6c71..4009a6d38c1 100644 --- a/pal/src/include/pal/file.h +++ b/pal/src/include/pal/file.h @@ -158,21 +158,6 @@ Close promary handles for stdin, stdout and stderr --*/ void FILECleanupStdHandles(void); -/*++ -FILEGetFileNameFromSymLink - -Input paramters: - -source = path to the file on input, path to the file with all - symbolic links traversed on return - -Note: Assumes the maximum size of the source is MAX_LONGPATH - -Return value: - TRUE on success, FALSE on failure ---*/ -BOOL FILEGetFileNameFromSymLink(char *source); - /*++ Function : diff --git a/pal/src/include/pal/file.hpp b/pal/src/include/pal/file.hpp index 909ba6c53df..e0775aaea25 100644 --- a/pal/src/include/pal/file.hpp +++ b/pal/src/include/pal/file.hpp @@ -194,15 +194,6 @@ namespace CorUnix char *szNameTemplate ); - /*++ - InternalDeleteFile - Wraps SYS_delete - --*/ - int - InternalDeleteFile( - const char *szPath - ); - /*++ InternalFgets Wraps fgets @@ -358,21 +349,6 @@ Close primary handles for stdin, stdout and stderr --*/ void FILECleanupStdHandles(void); -/*++ -FILEGetFileNameFromSymLink - -Input paramters: - -source = path to the file on input, path to the file with all - symbolic links traversed on return - -Note: Assumes the maximum size of the source is MAX_LONGPATH - -Return value: - TRUE on success, FALSE on failure ---*/ -BOOL FILEGetFileNameFromSymLink(char *source); - /*++ Function :