Skip to content

Commit 10fbe7b

Browse files
[MERGE #1393 @antonmes] Change how PAL file I/O functions treat symbolic links
Merge pull request #1393 from antonmes:linux Synchronize changes made by @adityamandaleeka in dotnet/coreclr#4922 Fixes build on macOS Sierra: `ChakraCore/pal/src/cruntime/filecrt.cpp:355:12: error: 'syscall' is deprecated: first deprecated in macOS 10.12 - syscall(2) is unsupported; please switch to a supported interface. For SYS_kdebug_trace use kdebug_signpost(). [-Werror,-Wdeprecated-declarations]`
2 parents 8aad2a5 + d8c8141 commit 10fbe7b

File tree

5 files changed

+4
-146
lines changed

5 files changed

+4
-146
lines changed

pal/src/cruntime/filecrt.cpp

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -332,34 +332,6 @@ PAL_unlink(const char *szPath)
332332
}
333333

334334

335-
/*++
336-
InternalDeleteFile
337-
338-
Wrapper that does the same thing as unlink, except that
339-
it uses the SYS_Delete system call present on Apple instead of unlink.
340-
341-
Input parameters:
342-
343-
szPath = a symbolic link or a hard link to a file
344-
345-
Return value:
346-
Returns 0 on success and -1 on failure
347-
--*/
348-
int
349-
CorUnix::InternalDeleteFile(
350-
const char *szPath
351-
)
352-
{
353-
int nRet = -1;
354-
#if defined(__APPLE__) && defined(SYS_delete)
355-
nRet = syscall(SYS_delete, szPath);
356-
#else
357-
nRet = unlink(szPath);
358-
#endif // defined(__APPLE__) && defined(SYS_delete)
359-
return nRet;
360-
}
361-
362-
363335
/*++
364336
PAL_rename
365337

pal/src/file/directory.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,6 @@ RemoveDirectoryHelper (
136136
*dwLastError = 0;
137137

138138
FILEDosToUnixPathA( lpPathName );
139-
if ( !FILEGetFileNameFromSymLink(lpPathName))
140-
{
141-
FILEGetProperNotFoundError( lpPathName, dwLastError );
142-
goto done;
143-
}
144139

145140
if ( rmdir(lpPathName) != 0 )
146141
{
@@ -179,7 +174,6 @@ RemoveDirectoryHelper (
179174
bRet = TRUE;
180175
}
181176

182-
done:
183177
return bRet;
184178
}
185179

pal/src/file/pal_file.cpp

Lines changed: 4 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,7 +1169,6 @@ DeleteFileA(
11691169
IN LPCSTR lpFileName)
11701170
{
11711171
PAL_ERROR palError = NO_ERROR;
1172-
DWORD dwShareMode = SHARE_MODE_NOT_INITALIZED;
11731172
CPalThread *pThread;
11741173
int result;
11751174
BOOL bRet = FALSE;
@@ -1196,12 +1195,6 @@ DeleteFileA(
11961195
lpUnixFileNamePS.CloseBuffer(length);
11971196

11981197
FILEDosToUnixPathA( lpUnixFileName );
1199-
1200-
if ( !FILEGetFileNameFromSymLink(lpUnixFileName))
1201-
{
1202-
dwLastError = FILEGetLastErrorFromErrnoAndFilename(lpUnixFileName);
1203-
goto done;
1204-
}
12051198

12061199
lpFullUnixFileName = reinterpret_cast<LPSTR>(InternalMalloc(cchFullUnixFileName));
12071200
if ( lpFullUnixFileName == NULL )
@@ -1228,31 +1221,9 @@ DeleteFileA(
12281221
}
12291222
}
12301223

1231-
palError = g_pFileLockManager->GetFileShareModeForFile(lpFullUnixFileName, &dwShareMode);
1232-
1233-
// Use unlink if we succesfully found the file to be opened with
1234-
// a FILE_SHARE_DELETE mode.
1235-
// Note that there is a window here where a race condition can occur:
1236-
// the check for the sharing mode and the unlink are two separate actions
1237-
// (not a single atomic action). So it's possible that between the check
1238-
// happening and the unlink happening, the file may have been closed. If
1239-
// it is just closed and not re-opened, no problems.
1240-
// If it is closed and re-opened without any sharing, we should be calling
1241-
// InternalDelete instead which would have failed.
1242-
// Instead, we call unlink which will succeed.
1224+
result = unlink( lpFullUnixFileName );
12431225

1244-
if (palError == NO_ERROR &&
1245-
dwShareMode != SHARE_MODE_NOT_INITALIZED &&
1246-
(dwShareMode & FILE_SHARE_DELETE) != 0)
1247-
{
1248-
result = unlink( lpFullUnixFileName );
1249-
}
1250-
else
1251-
{
1252-
result = InternalDeleteFile( lpFullUnixFileName );
1253-
}
1254-
1255-
if ( result < 0 )
1226+
if (result < 0)
12561227
{
12571228
TRACE("unlink returns %d\n", result);
12581229
dwLastError = FILEGetLastErrorFromErrnoAndFilename(lpFullUnixFileName);
@@ -1471,13 +1442,6 @@ MoveFileExA(
14711442

14721443
FILEDosToUnixPathA( dest );
14731444

1474-
if ( !FILEGetFileNameFromSymLink(source))
1475-
{
1476-
TRACE( "FILEGetFileNameFromSymLink failed\n" );
1477-
dwLastError = FILEGetLastErrorFromErrnoAndFilename(source);
1478-
goto done;
1479-
}
1480-
14811445
if ( !(dwFlags & MOVEFILE_REPLACE_EXISTING) )
14821446
{
14831447
#if HAVE_CASE_SENSITIVE_FILESYSTEM
@@ -1558,9 +1522,9 @@ MoveFileExA(
15581522
case ENOENT:
15591523
{
15601524
struct stat buf;
1561-
if (stat(source, &buf) == -1)
1525+
if (lstat(source, &buf) == -1)
15621526
{
1563-
FILEGetProperNotFoundError(dest, &dwLastError);
1527+
FILEGetProperNotFoundError(source, &dwLastError);
15641528
}
15651529
else
15661530
{
@@ -4951,39 +4915,6 @@ void FILECleanupStdHandles(void)
49514915
}
49524916

49534917

4954-
/*++
4955-
FILEGetFileNameFromSymLink
4956-
4957-
Input parameters:
4958-
4959-
source = path to the file on input, path to the file with all
4960-
symbolic links traversed on return
4961-
4962-
Note: Assumes the maximum size of the source is MAX_LONGPATH
4963-
4964-
Return value:
4965-
TRUE on success, FALSE on failure
4966-
--*/
4967-
BOOL FILEGetFileNameFromSymLink(char *source)
4968-
{
4969-
int ret;
4970-
char * sLinkData = (char*)InternalMalloc(MAX_LONGPATH);
4971-
4972-
do
4973-
{
4974-
ret = readlink(source, sLinkData, MAX_LONGPATH);
4975-
if (ret>0)
4976-
{
4977-
sLinkData[ret] = '\0';
4978-
strcpy_s(source, sizeof(char)*(MAX_LONGPATH), sLinkData);
4979-
}
4980-
} while (ret > 0);
4981-
4982-
InternalFree(sLinkData);
4983-
return (errno == EINVAL);
4984-
}
4985-
4986-
49874918
/*++
49884919
Function:
49894920
GetFileInformationByHandle

pal/src/include/pal/file.h

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -158,21 +158,6 @@ Close promary handles for stdin, stdout and stderr
158158
--*/
159159
void FILECleanupStdHandles(void);
160160

161-
/*++
162-
FILEGetFileNameFromSymLink
163-
164-
Input paramters:
165-
166-
source = path to the file on input, path to the file with all
167-
symbolic links traversed on return
168-
169-
Note: Assumes the maximum size of the source is MAX_LONGPATH
170-
171-
Return value:
172-
TRUE on success, FALSE on failure
173-
--*/
174-
BOOL FILEGetFileNameFromSymLink(char *source);
175-
176161
/*++
177162
178163
Function :

pal/src/include/pal/file.hpp

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -194,15 +194,6 @@ namespace CorUnix
194194
char *szNameTemplate
195195
);
196196

197-
/*++
198-
InternalDeleteFile
199-
Wraps SYS_delete
200-
--*/
201-
int
202-
InternalDeleteFile(
203-
const char *szPath
204-
);
205-
206197
/*++
207198
InternalFgets
208199
Wraps fgets
@@ -358,21 +349,6 @@ Close primary handles for stdin, stdout and stderr
358349
--*/
359350
void FILECleanupStdHandles(void);
360351

361-
/*++
362-
FILEGetFileNameFromSymLink
363-
364-
Input paramters:
365-
366-
source = path to the file on input, path to the file with all
367-
symbolic links traversed on return
368-
369-
Note: Assumes the maximum size of the source is MAX_LONGPATH
370-
371-
Return value:
372-
TRUE on success, FALSE on failure
373-
--*/
374-
BOOL FILEGetFileNameFromSymLink(char *source);
375-
376352
/*++
377353
378354
Function :

0 commit comments

Comments
 (0)