Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove FILEDosToUnixPathA conversion #78995

Merged
merged 5 commits into from
Dec 2, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 0 additions & 2 deletions src/coreclr/pal/src/cruntime/file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,6 @@ PAL_fopen(const char * fileName, const char * mode)
goto done;
}

FILEDosToUnixPathA( UnixFileName );

/*I am not checking for the case where stat fails
*as fopen will handle the error more gracefully in case
*UnixFileName is invalid*/
Expand Down
26 changes: 4 additions & 22 deletions src/coreclr/pal/src/file/directory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,6 @@ RemoveDirectoryHelper (
BOOL bRet = FALSE;
*dwLastError = 0;

FILEDosToUnixPathA( lpPathName );

if ( rmdir(lpPathName) != 0 )
{
TRACE("Removal of directory [%s] was unsuccessful, errno = %d.\n",
Expand Down Expand Up @@ -415,7 +413,6 @@ CreateDirectoryA(
dwLastError = ERROR_NOT_ENOUGH_MEMORY;
goto done;
}
FILEDosToUnixPathA( unixPathName );
// Remove any trailing slashes at the end because mkdir might not
// handle them appropriately on all platforms.
pathLength = strlen(unixPathName);
Expand Down Expand Up @@ -509,7 +506,6 @@ SetCurrentDirectoryA(
BOOL bRet = FALSE;
DWORD dwLastError = 0;
int result;
LPSTR unixPathName = NULL;

PERF_ENTRY(SetCurrentDirectoryA);
ENTRY("SetCurrentDirectoryA(lpPathName=%p (%s))\n",
Expand All @@ -525,17 +521,8 @@ SetCurrentDirectoryA(
goto done;
}

unixPathName = PAL__strdup(lpPathName);
if (unixPathName == NULL )
{
ERROR("PAL__strdup() failed\n");
dwLastError = ERROR_NOT_ENOUGH_MEMORY;
goto done;
}
FILEDosToUnixPathA( unixPathName );

TRACE("Attempting to open Unix dir [%s]\n", unixPathName);
result = chdir(unixPathName);
TRACE("Attempting to open Unix dir [%s]\n", lpPathName);
result = chdir(lpPathName);

if ( result == 0 )
{
Expand All @@ -547,15 +534,15 @@ SetCurrentDirectoryA(
{
struct stat stat_data;

if ( stat( unixPathName, &stat_data) == 0 &&
if ( stat( lpPathName, &stat_data) == 0 &&
(stat_data.st_mode & S_IFMT) == S_IFREG )
{
/* Not a directory, it is a file. */
dwLastError = ERROR_DIRECTORY;
}
else
{
FILEGetProperNotFoundError( unixPathName, &dwLastError );
FILEGetProperNotFoundError( lpPathName, &dwLastError );
}
TRACE("chdir() failed, path was invalid.\n");
}
Expand All @@ -573,11 +560,6 @@ SetCurrentDirectoryA(
SetLastError(dwLastError);
}

if(unixPathName != NULL)
{
PAL_free( unixPathName );
}

LOGEXIT("SetCurrentDirectoryA returns BOOL %d\n", bRet);
PERF_EXIT(SetCurrentDirectoryA);
return bRet;
Expand Down
75 changes: 12 additions & 63 deletions src/coreclr/pal/src/file/file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -461,8 +461,6 @@ CorUnix::InternalCreateFile(
goto done;
}

FILEDosToUnixPathA( lpUnixPath );

// Compute the absolute pathname to the file. This pathname is used
// to determine if two file names represent the same file.
palError = InternalCanonicalizeRealPath(lpUnixPath, lpFullUnixPath);
Expand Down Expand Up @@ -1031,8 +1029,6 @@ DeleteFileA(
goto done;
}

FILEDosToUnixPathA( lpunixFileName );

// 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 Down Expand Up @@ -1103,7 +1099,6 @@ GetFileAttributesA(
struct stat stat_data;
DWORD dwAttr = 0;
DWORD dwLastError = 0;
PathCharString unixFileName;

PERF_ENTRY(GetFileAttributesA);
ENTRY("GetFileAttributesA(lpFileName=%p (%s))\n", lpFileName?lpFileName:"NULL", lpFileName?lpFileName:"NULL");
Expand All @@ -1115,18 +1110,9 @@ GetFileAttributesA(
goto done;
}


if( !unixFileName.Set(lpFileName, strlen(lpFileName)))
{
dwLastError = ERROR_NOT_ENOUGH_MEMORY;
goto done;
}

FILEDosToUnixPathA( unixFileName );

if ( stat(unixFileName, &stat_data) != 0 )
if ( stat(lpFileName, &stat_data) != 0 )
{
dwLastError = FILEGetLastErrorFromErrnoAndFilename(unixFileName);
dwLastError = FILEGetLastErrorFromErrnoAndFilename(lpFileName);
goto done;
}

Expand Down Expand Up @@ -1311,7 +1297,6 @@ GetFileAttributesExW(
goto done;
}

FILEDosToUnixPathA(name);
/* do the stat */
if ( stat(name, &stat_data) != 0 )
{
Expand Down Expand Up @@ -1386,7 +1371,6 @@ SetFileAttributesA(

DWORD dwLastError = 0;
BOOL bRet = FALSE;
LPSTR unixFileName = NULL;

PERF_ENTRY(SetFileAttributesA);
ENTRY("SetFileAttributesA(lpFileName=%p (%s), dwFileAttributes=%#x)\n",
Expand Down Expand Up @@ -1422,19 +1406,11 @@ SetFileAttributesA(
goto done;
}

if ((unixFileName = strdup(lpFileName)) == NULL)
{
ERROR("strdup() failed\n");
dwLastError = ERROR_NOT_ENOUGH_MEMORY;
goto done;
}

FILEDosToUnixPathA( unixFileName );
if ( stat(unixFileName, &stat_data) != 0 )
if ( stat(lpFileName, &stat_data) != 0 )
{
TRACE("stat failed on %s; errno is %d (%s)\n",
unixFileName, errno, strerror(errno));
dwLastError = FILEGetLastErrorFromErrnoAndFilename(unixFileName);
lpFileName, errno, strerror(errno));
dwLastError = FILEGetLastErrorFromErrnoAndFilename(lpFileName);
goto done;
}

Expand Down Expand Up @@ -1470,10 +1446,10 @@ SetFileAttributesA(
bRet = TRUE;
if ( new_mode != stat_data.st_mode )
{
if ( chmod(unixFileName, new_mode) != 0 )
if ( chmod(lpFileName, new_mode) != 0 )
{
ERROR("chmod(%s, %#x) failed\n", unixFileName, new_mode);
dwLastError = FILEGetLastErrorFromErrnoAndFilename(unixFileName);
ERROR("chmod(%s, %#x) failed\n", lpFileName, new_mode);
dwLastError = FILEGetLastErrorFromErrnoAndFilename(lpFileName);
bRet = FALSE;
}
}
Expand All @@ -1484,8 +1460,6 @@ SetFileAttributesA(
pThread->SetLastError(dwLastError);
}

free(unixFileName);

LOGEXIT("SetFileAttributesA returns BOOL %d\n", bRet);
PERF_EXIT(SetFileAttributesA);
return bRet;
Expand Down Expand Up @@ -2666,7 +2640,6 @@ GetTempFileNameA(
{
strncat_s( file_template, file_templatePS.GetSizeOf(), lpPrefixString, MAX_PREFIX );
}
FILEDosToUnixPathA( file_template );
strncat_s( file_template, file_templatePS.GetSizeOf(), "%.4x.TMP", MAX_SEEDSIZE );

/* Create the file. */
Expand Down Expand Up @@ -3017,7 +2990,6 @@ CopyFileA(
DWORD dwSrcFileAttributes;
struct stat SrcFileStats;

LPSTR lpUnixPath = NULL;
const int buffer_size = 16*1024;
char *buffer = (char*)alloca(buffer_size);
DWORD bytes_read;
Expand Down Expand Up @@ -3065,18 +3037,10 @@ CopyFileA(
}

/* Need to preserve the owner/group and chmod() flags */
lpUnixPath = strdup(lpExistingFileName);
if ( lpUnixPath == NULL )
{
ERROR("strdup() failed\n");
pThread->SetLastError(FILEGetLastErrorFromErrno());
goto done;
}
FILEDosToUnixPathA(lpUnixPath);
if (stat (lpUnixPath, &SrcFileStats) == -1)
if (stat (lpExistingFileName, &SrcFileStats) == -1)
{
ERROR("stat() failed for %s\n", lpExistingFileName);
pThread->SetLastError(FILEGetLastErrorFromErrnoAndFilename(lpUnixPath));
pThread->SetLastError(FILEGetLastErrorFromErrnoAndFilename(lpExistingFileName));
goto done;
}

Expand All @@ -3094,17 +3058,6 @@ CopyFileA(
goto done;
}

free(lpUnixPath);
lpUnixPath = strdup(lpNewFileName);
if ( lpUnixPath == NULL )
{
ERROR("strdup() failed\n");
pThread->SetLastError(FILEGetLastErrorFromErrno());
goto done;
}
FILEDosToUnixPathA( lpUnixPath );


// We don't set file attributes in CreateFile. The only attribute
// that is reflected on disk in Unix is read-only, and we set that
// here.
Expand All @@ -3115,11 +3068,11 @@ CopyFileA(
}

/* Make sure the new file has the same chmod() flags. */
if (chmod(lpUnixPath, SrcFileStats.st_mode & permissions) == -1)
if (chmod(lpNewFileName, SrcFileStats.st_mode & permissions) == -1)
{
WARN ("chmod() failed to set mode 0x%x on new file\n",
SrcFileStats.st_mode & permissions);
pThread->SetLastError(FILEGetLastErrorFromErrnoAndFilename(lpUnixPath));
pThread->SetLastError(FILEGetLastErrorFromErrnoAndFilename(lpNewFileName));
goto done;
}

Expand Down Expand Up @@ -3155,10 +3108,6 @@ CopyFileA(
{
CloseHandle( hDest );
}
if (lpUnixPath)
{
free(lpUnixPath);
}

LOGEXIT("CopyFileA returns BOOL %d\n", bGood);
PERF_EXIT(CopyFileA);
Expand Down
6 changes: 0 additions & 6 deletions src/coreclr/pal/src/file/find.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ FindFirstFileA(
SetLastError( ERROR_INTERNAL_ERROR );
goto done;
}
FILEDosToUnixPathA( lpTemp );
FILEGetProperNotFoundError( lpTemp, &dwLastError );

if ( ERROR_PATH_NOT_FOUND == dwLastError )
Expand Down Expand Up @@ -909,11 +908,6 @@ static BOOL FILEDosGlobA( CPalThread *pthrCurrent,
goto done;
}

if (Dir[0] != 0)
{
FILEDosToUnixPathA( Dir );
}

/* The meat of the routine happens below. Basically, there are three
special things to check for:

Expand Down
53 changes: 0 additions & 53 deletions src/coreclr/pal/src/file/path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,6 @@ GetFullPathNameA(
}

unixPathBuf = unixPath.OpenStringBuffer(unixPath.GetCount());
/* do conversion to Unix path */
FILEDosToUnixPathA( unixPathBuf );

/* now we can canonicalize this */
FILECanonicalizePath(unixPathBuf);
Expand Down Expand Up @@ -433,57 +431,6 @@ GetTempPathW(
}



/*++
Function:
FileDosToUnixPathA

Abstract:
Change a DOS path to a Unix path.

Replaces '\' by '/'

Parameter:
IN/OUT lpPath: path to be modified
--*/
void
FILEDosToUnixPathA(
LPSTR lpPath)
{
LPSTR p;

TRACE("Original DOS path = [%s]\n", lpPath);

if (!lpPath)
{
return;
}

for (p = lpPath; *p; p++)
{
/* Replace \ with / */
if (*p == '\\')
{
*p = '/';
}
}

TRACE("Resulting Unix path = [%s]\n", lpPath);
}

void
FILEDosToUnixPathA(
PathCharString& lpPath)
{

SIZE_T len = lpPath.GetCount();
LPSTR lpPathBuf = lpPath.OpenStringBuffer(len);
FILEDosToUnixPathA(lpPathBuf);
lpPath.CloseBuffer(len);

}


/*++
Function:
FILEGetDirectoryFromFullPathA
Expand Down
13 changes: 0 additions & 13 deletions src/coreclr/pal/src/include/pal/file.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,6 @@ Notes :
--*/
void FILECanonicalizePath(LPSTR lpUnixPath);

/*++
Function:
FileDosToUnixPathA

Abstract:
Change a DOS path to a Unix path. Replace '\' by '/'.

Parameter:
IN/OUT lpPath: path to be modified
--*/
void
FILEDosToUnixPathA(LPSTR lpPath);

/*++
Function:
FILEGetDirectoryFromFullPathA
Expand Down
13 changes: 0 additions & 13 deletions src/coreclr/pal/src/include/pal/file.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,19 +190,6 @@ Notes :
--*/
void FILECanonicalizePath(LPSTR lpUnixPath);

/*++
Function:
FileDosToUnixPathA

Abstract:
Change a DOS path to a Unix path. Replace '\' by '/'.

Parameter:
IN/OUT lpPath: path to be modified
--*/
void
FILEDosToUnixPathA(LPSTR lpPath);

/*++
Function:
FILEGetDirectoryFromFullPathA
Expand Down
Loading