From 1c4b1f654a9f116b1a3936cc67a24044091884f5 Mon Sep 17 00:00:00 2001 From: Aditya Mandaleeka Date: Thu, 12 May 2016 18:04:47 -0700 Subject: [PATCH] Stop using SYS_delete syscall for deleting files. Commit migrated from https://github.com/dotnet/coreclr/commit/d85869805ebda80514d77fa946afddfd36794073 --- src/coreclr/src/pal/src/cruntime/filecrt.cpp | 28 --------------------------- src/coreclr/src/pal/src/file/file.cpp | 29 +++------------------------- src/coreclr/src/pal/src/include/pal/file.hpp | 9 --------- 3 files changed, 3 insertions(+), 63 deletions(-) diff --git a/src/coreclr/src/pal/src/cruntime/filecrt.cpp b/src/coreclr/src/pal/src/cruntime/filecrt.cpp index e901a0d..48079b3 100644 --- a/src/coreclr/src/pal/src/cruntime/filecrt.cpp +++ b/src/coreclr/src/pal/src/cruntime/filecrt.cpp @@ -312,34 +312,6 @@ CorUnix::InternalOpen( /*++ -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 Wrapper function for rename. diff --git a/src/coreclr/src/pal/src/file/file.cpp b/src/coreclr/src/pal/src/file/file.cpp index f7ce43a..2a0d55b 100644 --- a/src/coreclr/src/pal/src/file/file.cpp +++ b/src/coreclr/src/pal/src/file/file.cpp @@ -1094,7 +1094,6 @@ DeleteFileA( IN LPCSTR lpFileName) { PAL_ERROR palError = NO_ERROR; - DWORD dwShareMode = SHARE_MODE_NOT_INITALIZED; CPalThread *pThread; int result; BOOL bRet = FALSE; @@ -1127,31 +1126,9 @@ DeleteFileA( } } - palError = g_pFileLockManager->GetFileShareModeForFile(lpFullunixFileName, &dwShareMode); + result = unlink( lpFullunixFileName ); - // 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. - - 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); @@ -1166,12 +1143,12 @@ done: { pThread->SetLastError( dwLastError ); } + LOGEXIT("DeleteFileA returns BOOL %d\n", bRet); PERF_EXIT(DeleteFileA); return bRet; } - /*++ Function: DeleteFileW diff --git a/src/coreclr/src/pal/src/include/pal/file.hpp b/src/coreclr/src/pal/src/include/pal/file.hpp index 4a416b1..5acccb0 100644 --- a/src/coreclr/src/pal/src/include/pal/file.hpp +++ b/src/coreclr/src/pal/src/include/pal/file.hpp @@ -192,15 +192,6 @@ namespace CorUnix ); /*++ - InternalDeleteFile - Wraps SYS_delete - --*/ - int - InternalDeleteFile( - const char *szPath - ); - - /*++ InternalFgets Wraps fgets --*/ -- 2.7.4