WebKit Bugzilla
Attachment 361321 Details for
Bug 194344
: [WTF] Add getting/changing current working directory to FileSystem
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Add get/change current working directory functions
194344.1.diff (text/plain), 10.33 KB, created by
Stephan Szabo
on 2019-02-06 13:27:04 PST
(
hide
)
Description:
Add get/change current working directory functions
Filename:
MIME Type:
Creator:
Stephan Szabo
Created:
2019-02-06 13:27:04 PST
Size:
10.33 KB
patch
obsolete
>diff --git a/Source/WTF/ChangeLog b/Source/WTF/ChangeLog >index 13ca9221fd9..efe6c232441 100644 >--- a/Source/WTF/ChangeLog >+++ b/Source/WTF/ChangeLog >@@ -1,3 +1,29 @@ >+2019-02-06 Stephan Szabo <stephan.szabo@sony.com> >+ >+ [WTF] Add getting/changing current working directory to FileSystem >+ https://bugs.webkit.org/show_bug.cgi?id=194344 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ * wtf/FileSystem.h: >+ Add new getCurrentWorkingDirectory and >+ changeCurrentWorkingDirectory methods. >+ * wtf/PlatformPlayStation.cmake: >+ Add new FileSystemPlayStation.cpp to build >+ * wtf/glib/FileSystemGlib.cpp: >+ (WTF::FileSystemImpl::getCurrentWorkingDirectory): >+ (WTF::FileSystemImpl::changeCurrentWorkingDirectory): >+ * wtf/playstation/FileSystemPlayStation.cpp: Added. >+ Simulate having a working directory for this platform. >+ (WTF::FileSystemImpl::getCurrentWorkingDirectory): >+ (WTF::FileSystemImpl::changeCurrentWorkingDirectory): >+ * wtf/posix/FileSystemPOSIX.cpp: >+ (WTF::FileSystemImpl::getCurrentWorkingDirectory): >+ (WTF::FileSystemImpl::changeCurrentWorkingDirectory): >+ * wtf/win/FileSystemWin.cpp: >+ (WTF::FileSystemImpl::getCurrentWorkingDirectory): >+ (WTF::FileSystemImpl::changeCurrentWorkingDirectory): >+ > 2019-02-03 Commit Queue <commit-queue@webkit.org> > > Unreviewed, rolling out r240896. >diff --git a/Source/WTF/wtf/FileSystem.h b/Source/WTF/wtf/FileSystem.h >index 903962ad46d..81ea90b805c 100644 >--- a/Source/WTF/wtf/FileSystem.h >+++ b/Source/WTF/wtf/FileSystem.h >@@ -187,6 +187,9 @@ WTF_EXPORT_PRIVATE bool deleteNonEmptyDirectory(const String&); > > WTF_EXPORT_PRIVATE String realPath(const String&); > >+WTF_EXPORT_PRIVATE String getCurrentWorkingDirectory(); >+WTF_EXPORT_PRIVATE bool changeCurrentWorkingDirectory(const String &); >+ > class MappedFileData { > public: > MappedFileData() { } >diff --git a/Source/WTF/wtf/PlatformPlayStation.cmake b/Source/WTF/wtf/PlatformPlayStation.cmake >index 4b6919076f3..937812a2e3c 100644 >--- a/Source/WTF/wtf/PlatformPlayStation.cmake >+++ b/Source/WTF/wtf/PlatformPlayStation.cmake >@@ -5,6 +5,8 @@ list(APPEND WTF_SOURCES > generic/RunLoopGeneric.cpp > generic/WorkQueueGeneric.cpp > >+ playstation/FileSystemPlayStation.cpp >+ > posix/FileSystemPOSIX.cpp > posix/OSAllocatorPOSIX.cpp > posix/ThreadingPOSIX.cpp >diff --git a/Source/WTF/wtf/glib/FileSystemGlib.cpp b/Source/WTF/wtf/glib/FileSystemGlib.cpp >index c3ec99a3d1b..361b5cd3d3c 100644 >--- a/Source/WTF/wtf/glib/FileSystemGlib.cpp >+++ b/Source/WTF/wtf/glib/FileSystemGlib.cpp >@@ -465,5 +465,16 @@ bool unlockFile(PlatformFileHandle handle) > } > #endif // USE(FILE_LOCK) > >+String getCurrentWorkingDirectory() >+{ >+ return stringFromFileSystemRepresentation(g_get_current_dir()); >+} >+ >+bool changeCurrentWorkingDirectory(const String &filePath) >+{ >+ CString fsRep = fileSystemRepresentation(filePath); >+ return !chdir(fsRep.data()); >+} >+ > } // namespace FileSystemImpl > } // namespace WTF >diff --git a/Source/WTF/wtf/playstation/FileSystemPlayStation.cpp b/Source/WTF/wtf/playstation/FileSystemPlayStation.cpp >new file mode 100644 >index 00000000000..4366e983701 >--- /dev/null >+++ b/Source/WTF/wtf/playstation/FileSystemPlayStation.cpp >@@ -0,0 +1,54 @@ >+/* >+ * Copyright (C) 2019 Sony Interactive Entertainment Inc. >+ * >+ * Redistribution and use in source and binary forms, with or without >+ * modification, are permitted provided that the following conditions >+ * are met: >+ * >+ * 1. Redistributions of source code must retain the above copyright >+ * notice, this list of conditions and the following disclaimer. >+ * 2. Redistributions in binary form must reproduce the above copyright >+ * notice, this list of conditions and the following disclaimer in the >+ * documentation and/or other materials provided with the distribution. >+ * 3. Neither the name of Apple Inc. ("Apple") nor the names of >+ * its contributors may be used to endorse or promote products derived >+ * from this software without specific prior written permission. >+ * >+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY >+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED >+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE >+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY >+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES >+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; >+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND >+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT >+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF >+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. >+ */ >+#include "config.h" >+#include <wtf/FileSystem.h> >+#include <wtf/text/StringBuilder.h> >+ >+namespace WTF { >+ >+namespace FileSystemImpl { >+ >+char currentWorkingDirectory[PATH_MAX] = {0}; >+ >+String getCurrentWorkingDirectory() >+{ >+ return stringFromFileSystemRepresentation(currentWorkingDirectory); >+} >+ >+bool changeCurrentWorkingDirectory(const String &filePath) >+{ >+ CString path = fileSystemRepresentation(filePath); >+ if (path.length() > sizeof(currentWorkingDirectory) - 1) >+ return false; >+ strncpy(currentWorkingDirectory, path.data(), sizeof(currentWorkingDirectory)); >+ currentWorkingDirectory[sizeof(currentWorkingDirectory)-1] = 0; >+ return true; >+} >+ >+} // namespace FileSystemImpl >+} // namespace WTF >diff --git a/Source/WTF/wtf/posix/FileSystemPOSIX.cpp b/Source/WTF/wtf/posix/FileSystemPOSIX.cpp >index 70d2f98e4d7..0a3f281c6c8 100644 >--- a/Source/WTF/wtf/posix/FileSystemPOSIX.cpp >+++ b/Source/WTF/wtf/posix/FileSystemPOSIX.cpp >@@ -492,5 +492,21 @@ String realPath(const String& filePath) > return result ? String::fromUTF8(result) : filePath; > } > >+#if !PLATFORM(PLAYSTATION) >+String getCurrentWorkingDirectory() >+{ >+ char workingDirectory[PATH_MAX]; >+ if (!getcwd(workingDirectory, sizeof(workingDirectory))) >+ return ""; >+ return stringFromFileSystemRepresentation(workingDirectory); >+} >+ >+bool changeCurrentWorkingDirectory(const String &filePath) >+{ >+ CString fsRep = fileSystemRepresentation(filePath); >+ return !chdir(fsRep.data()); >+} >+#endif >+ > } // namespace FileSystemImpl > } // namespace WTF >diff --git a/Source/WTF/wtf/win/FileSystemWin.cpp b/Source/WTF/wtf/win/FileSystemWin.cpp >index d672af63746..607315b5077 100644 >--- a/Source/WTF/wtf/win/FileSystemWin.cpp >+++ b/Source/WTF/wtf/win/FileSystemWin.cpp >@@ -582,5 +582,24 @@ bool deleteNonEmptyDirectory(const String& directoryPath) > return !SHFileOperation(&deleteOperation); > } > >+String getCurrentWorkingDirectory() >+{ >+ DWORD bufferLength = ::GetCurrentDirectoryW(0, nullptr); >+ if (!bufferLength) >+ return ""; >+ // In Windows, wchar_t is the UTF-16LE. >+ // https://msdn.microsoft.com/en-us/library/dd374081.aspx >+ // https://msdn.microsoft.com/en-us/library/windows/desktop/ff381407.aspx >+ Vector<wchar_t> buffer(bufferLength); >+ DWORD lengthNotIncludingNull = ::GetCurrentDirectoryW(bufferLength, buffer.data()); >+ return wcharToString(buffer.data(), lengthNotIncludingNull); >+} >+ >+bool changeCurrentWorkingDirectory(const String &filePath) >+{ >+ String destination = filePath; >+ return SetCurrentDirectoryW(stringToNullTerminatedWChar(destination).data()); >+} >+ > } // namespace FileSystemImpl > } // namespace WTF >diff --git a/Tools/ChangeLog b/Tools/ChangeLog >index 1c2a54e926a..bc77b5e8364 100644 >--- a/Tools/ChangeLog >+++ b/Tools/ChangeLog >@@ -1,3 +1,17 @@ >+2019-02-06 Stephan Szabo <stephan.szabo@sony.com> >+ >+ [WTF] Add getting/changing current working directory to FileSystem >+ https://bugs.webkit.org/show_bug.cgi?id=194344 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ Add test for WTF::FileSystem::getCurrentWorkingDirectory and >+ WTF::FileSystem::changeCurrentWorkingDirectory. >+ >+ * TestWebKitAPI/Tests/WTF/FileSystem.cpp: >+ (TestWebKitAPI::FileSystemTest::tempDirectoryPath): >+ (TestWebKitAPI::TEST_F): >+ > 2019-02-03 Fujii Hironori <Hironori.Fujii@sony.com> > > [Win] WebKitTestRunners is failing to create the IndexedDB directory. >diff --git a/Tools/TestWebKitAPI/Tests/WTF/FileSystem.cpp b/Tools/TestWebKitAPI/Tests/WTF/FileSystem.cpp >index 830552556de..fbb9c7f58fa 100644 >--- a/Tools/TestWebKitAPI/Tests/WTF/FileSystem.cpp >+++ b/Tools/TestWebKitAPI/Tests/WTF/FileSystem.cpp >@@ -63,6 +63,9 @@ public: > > m_quoteContainingFilePath = FileSystem::openTemporaryFile("temp\"Empty\"TestFile", handle); > FileSystem::closeFile(handle); >+ >+ m_tempDirectoryPath = FileSystem::pathByAppendingComponent(FileSystem::directoryName(m_tempEmptyFilePath), "tempDirectory"); >+ FileSystem::makeAllDirectories(m_tempDirectoryPath); > } > > void TearDown() override >@@ -73,6 +76,7 @@ public: > FileSystem::deleteFile(m_spaceContainingFilePath); > FileSystem::deleteFile(m_bangContainingFilePath); > FileSystem::deleteFile(m_quoteContainingFilePath); >+ FileSystem::deleteEmptyDirectory(m_tempDirectoryPath); > } > > const String& tempFilePath() { return m_tempFilePath; } >@@ -81,6 +85,7 @@ public: > const String& spaceContainingFilePath() { return m_spaceContainingFilePath; } > const String& bangContainingFilePath() { return m_bangContainingFilePath; } > const String& quoteContainingFilePath() { return m_quoteContainingFilePath; } >+ const String& tempDirectoryPath() { return m_tempDirectoryPath; } > > private: > String m_tempFilePath; >@@ -89,6 +94,7 @@ private: > String m_spaceContainingFilePath; > String m_bangContainingFilePath; > String m_quoteContainingFilePath; >+ String m_tempDirectoryPath; > }; > > TEST_F(FileSystemTest, MappingMissingFile) >@@ -145,4 +151,15 @@ TEST_F(FileSystemTest, UnicodeDirectoryName) > EXPECT_TRUE(expectedDirectoryName == directoryName); > } > >+TEST_F(FileSystemTest, CurrentWorkingDirectory) >+{ >+ auto originalPath = FileSystem::getCurrentWorkingDirectory(); >+ auto change = FileSystem::changeCurrentWorkingDirectory(tempDirectoryPath()); >+ EXPECT_TRUE(change); >+ auto newPath = FileSystem::getCurrentWorkingDirectory(); >+ EXPECT_TRUE(newPath == tempDirectoryPath()); >+ auto changeBack = FileSystem::changeCurrentWorkingDirectory(originalPath); >+ EXPECT_TRUE(changeBack); >+} >+ > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 194344
:
361321
|
361404
|
361644
|
361645