Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 0 additions & 28 deletions src/pal/src/cruntime/filecrt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,34 +311,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

Expand Down
7 changes: 0 additions & 7 deletions src/pal/src/file/directory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,6 @@ RemoveDirectoryHelper (

FILEDosToUnixPathA( lpPathName );

if ( !FILEGetFileNameFromSymLink(lpPathName))
{
FILEGetProperNotFoundError( lpPathName, dwLastError );
goto done;
}

if ( rmdir(lpPathName) != 0 )
{
TRACE("Removal of directory [%s] was unsuccessful, errno = %d.\n",
Expand Down Expand Up @@ -177,7 +171,6 @@ RemoveDirectoryHelper (
bRet = TRUE;
}

done:
return bRet;
}

Expand Down
87 changes: 6 additions & 81 deletions src/pal/src/file/file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -1115,12 +1114,6 @@ DeleteFileA(

FILEDosToUnixPathA( lpunixFileName );

if ( !FILEGetFileNameFromSymLink(lpunixFileName))
{
dwLastError = FILEGetLastErrorFromErrnoAndFilename(lpunixFileName);
goto done;
}

// Compute the absolute pathname to the file. This pathname is used
// to determine if two file names represent the same file.
palError = InternalCanonicalizeRealPath(lpunixFileName, lpFullunixFileName);
Expand All @@ -1133,31 +1126,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.

if (palError == NO_ERROR &&
dwShareMode != SHARE_MODE_NOT_INITALIZED &&
(dwShareMode & FILE_SHARE_DELETE) != 0)
{
result = unlink( lpFullunixFileName );
}
else
{
result = InternalDeleteFile( lpFullunixFileName );
}
result = unlink( lpFullunixFileName );

if ( result < 0 )
if (result < 0)
{
TRACE("unlink returns %d\n", result);
dwLastError = FILEGetLastErrorFromErrnoAndFilename(lpFullunixFileName);
Expand All @@ -1172,12 +1143,12 @@ DeleteFileA(
{
pThread->SetLastError( dwLastError );
}

LOGEXIT("DeleteFileA returns BOOL %d\n", bRet);
PERF_EXIT(DeleteFileA);
return bRet;
}


/*++
Function:
DeleteFileW
Expand Down Expand Up @@ -1350,15 +1321,8 @@ MoveFileExA(
dwLastError = ERROR_NOT_ENOUGH_MEMORY;
goto done;
}

FILEDosToUnixPathA( dest );

if ( !FILEGetFileNameFromSymLink(source))
{
TRACE( "FILEGetFileNameFromSymLink failed\n" );
dwLastError = FILEGetLastErrorFromErrnoAndFilename(source);
goto done;
}
FILEDosToUnixPathA( dest );

if ( !(dwFlags & MOVEFILE_REPLACE_EXISTING) )
{
Expand Down Expand Up @@ -1440,9 +1404,9 @@ MoveFileExA(
case ENOENT:
{
struct stat buf;
if (stat(source, &buf) == -1)
if (lstat(source, &buf) == -1)
{
FILEGetProperNotFoundError(dest, &dwLastError);
FILEGetProperNotFoundError(source, &dwLastError);
}
else
{
Expand Down Expand Up @@ -4754,7 +4718,6 @@ BOOL FILEInitStdHandles(void)
return FALSE;
}


/*++
FILECleanupStdHandles

Expand Down Expand Up @@ -4794,44 +4757,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

Return value:
TRUE on success, FALSE on failure
--*/
BOOL FILEGetFileNameFromSymLink(PathCharString& source)
{
int ret;
PathCharString sLinkDataString;
struct stat sb;

do
{
if (lstat(source, &sb) == -1)
{
break;
}

char * sLinkData = sLinkDataString.OpenStringBuffer(sb.st_size);
ret = readlink(source, sLinkData, sb.st_size);
if (ret > 0)
{
sLinkDataString.CloseBuffer(ret);
source.Set(sLinkDataString);
}
} while (ret > 0);

return (errno == EINVAL);
}


/*++
Function:
GetFileInformationByHandle
Expand Down
14 changes: 0 additions & 14 deletions src/pal/src/include/pal/file.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,20 +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


Return value:
TRUE on success, FALSE on failure
--*/
BOOL FILEGetFileNameFromSymLink(PathCharString& source);

/*++

Function :
Expand Down
23 changes: 0 additions & 23 deletions src/pal/src/include/pal/file.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,15 +191,6 @@ namespace CorUnix
char *szNameTemplate
);

/*++
InternalDeleteFile
Wraps SYS_delete
--*/
int
InternalDeleteFile(
const char *szPath
);

/*++
InternalFgets
Wraps fgets
Expand Down Expand Up @@ -355,20 +346,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


Return value:
TRUE on success, FALSE on failure
BOOL FILEGetFileNameFromSymLink(PathCharString& source);
--*/

/*++

Function :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2)
set(CMAKE_INCLUDE_CURRENT_DIR ON)

set(SOURCES
DeleteFileA.c
DeleteFileA.cpp
)

add_executable(paltest_deletefilea_test1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@
// delete a file without proper permissions
//

#define PAL_STDCPP_COMPAT
#include <palsuite.h>
#undef PAL_STDCPP_COMPAT

#include <unistd.h>
#include <sys/stat.h>


int __cdecl main(int argc, char *argv[])
Expand All @@ -35,7 +39,7 @@ int __cdecl main(int argc, char *argv[])
}

//
// deleting an existing file
// create a test file
//
tempFile = fopen("testFile01.txt", "w");
if (tempFile == NULL)
Expand All @@ -51,6 +55,34 @@ int __cdecl main(int argc, char *argv[])
" testFile01.txt\"\n");
}

//
// delete a symlink to an existing file
//
if (symlink("testFile01.txt", "testFile01_symlink") != 0)
{
Fail("DeleteFileA: ERROR: Failed to create a symlink to testFile01.txt.\n");
}

bRc = DeleteFileA("testFile01_symlink");
if (bRc != TRUE)
{
Fail ("DeleteFileA: ERROR: Couldn't delete symlink!\n Error is %d\n", GetLastError());
}

struct stat statBuffer;
if (lstat("testFile01.txt", &statBuffer) != 0)
{
Fail("DeleteFileA: ERROR: Deleting a symlink deleted the file it was pointing to.\n");
}

if (lstat("testFile01_symlink", &statBuffer) == 0)
{
Fail("DeleteFileA: ERROR: Failed to delete a symlink.\n");
}

//
// deleting an existing file
//
bRc = DeleteFileA("testFile01.txt");
if (bRc != TRUE)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2)
set(CMAKE_INCLUDE_CURRENT_DIR ON)

set(SOURCES
RemoveDirectoryA.c
RemoveDirectoryA.cpp
)

add_executable(paltest_removedirectorya_test1
Expand Down
Loading