Skip to content
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 pal/src/cruntime/filecrt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 0 additions & 6 deletions pal/src/file/directory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,6 @@ RemoveDirectoryHelper (
*dwLastError = 0;

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

if ( rmdir(lpPathName) != 0 )
{
Expand Down Expand Up @@ -179,7 +174,6 @@ RemoveDirectoryHelper (
bRet = TRUE;
}

done:
return bRet;
}

Expand Down
77 changes: 4 additions & 73 deletions pal/src/file/pal_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -1196,12 +1195,6 @@ DeleteFileA(
lpUnixFileNamePS.CloseBuffer(length);

FILEDosToUnixPathA( lpUnixFileName );

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

lpFullUnixFileName = reinterpret_cast<LPSTR>(InternalMalloc(cchFullUnixFileName));
if ( lpFullUnixFileName == NULL )
Expand All @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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
Expand Down
15 changes: 0 additions & 15 deletions pal/src/include/pal/file.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 :
Expand Down
24 changes: 0 additions & 24 deletions pal/src/include/pal/file.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,15 +194,6 @@ namespace CorUnix
char *szNameTemplate
);

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

/*++
InternalFgets
Wraps fgets
Expand Down Expand Up @@ -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 :
Expand Down