getFileMetadata() does not work as expected for symbolic links
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 31 Aug 2017 20:53:38 +0000 (20:53 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 31 Aug 2017 20:53:38 +0000 (20:53 +0000)
commitf29e3ba77c903e69023913b7b4b55c9938cd9613
treed7b3149889e9491a5d72724b10744e61930d0745
parentfd2597a1d37bad29b8904ecf2106cc82098ad084
getFileMetadata() does not work as expected for symbolic links
https://bugs.webkit.org/show_bug.cgi?id=176143

Reviewed by Andreas Kling.

Source/WebCore:

getFileMetadata() does not work as expected for symbolic links:
On POSIX, getFileMetadata() always followed symlinks, which meant that FileMetadata.type could
never be TypeSymbolicLink. On Windows, the function properly did not follow symlinks but failed to set
FileMetadata.type to TypeSymbolicLink when the file was a symbolic link.

This patch adds a new ShouldFollowSymbolicLinks parameter to getFileMetadata() so that
the call site can decide the behavior it wants. If getFileMetadata() is called on a
symbolic link with ShouldFollowSymbolicLinks::No as parameter, FileMetadata.type is now
properly set to TypeSymbolicLink.

No new tests, covered by new API test.

* Modules/entriesapi/DOMFileSystem.cpp:
(WebCore::listDirectoryWithMetadata):
It is important we do not follow symlinks here since the code wants to discard them
and does so by checking FileMetadata.type.

* WebCore.xcodeproj/project.pbxproj:
* fileapi/File.cpp:
(WebCore::File::isDirectory const):

* html/FileListCreator.cpp:
(WebCore::appendDirectoryFiles):
(WebCore::FileListCreator::createFileList):
It is important we do not follow symlinks here since the code wants to discard them
and does so by checking FileMetadata.type.

* platform/FileSystem.cpp:
(WebCore::fileIsDirectory):
* platform/FileSystem.h:
* platform/glib/FileSystemGlib.cpp:
(WebCore::getFileLStat):
(WebCore::getFileMetadata):
* platform/posix/FileSystemPOSIX.cpp:
(WebCore::getFileMetadata):
(WebCore::createSymbolicLink):
* platform/win/FileSystemWin.cpp:
(WebCore::getFinalPathName):
(WebCore::getFileMetadata):
(WebCore::createSymbolicLink):
- Add new createSymbolicLink() function for testing purposes.
- On Posix, call lstat() instead of stat if ShouldFollowSymbolicLinks::No.
- On Windows, since FindFirstFileW() does not follow symlinks, resolve
  final path using GetFinalPathNameByHandleW() if ShouldFollowSymbolicLinks::Yes.
- On Windows, properly set FileMetadata.type to TypeSymbolicLink if the file
  is a symbolic link.

Tools:

Add API test coverage.

* TestWebKitAPI/Tests/WebCore/FileSystem.cpp:
(TestWebKitAPI::TEST_F):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@221441 268f45cc-cd09-0410-ab3c-d52691b4dbfc
14 files changed:
Source/WebCore/ChangeLog
Source/WebCore/Modules/entriesapi/DOMFileSystem.cpp
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/fileapi/File.cpp
Source/WebCore/html/FileListCreator.cpp
Source/WebCore/platform/FileSystem.cpp
Source/WebCore/platform/FileSystem.h
Source/WebCore/platform/glib/FileSystemGlib.cpp
Source/WebCore/platform/network/BlobDataFileReference.cpp
Source/WebCore/platform/network/mac/BlobDataFileReferenceMac.mm
Source/WebCore/platform/posix/FileSystemPOSIX.cpp
Source/WebCore/platform/win/FileSystemWin.cpp
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WebCore/FileSystem.cpp