mirror of
https://github.com/etlegacy/Update-Installer.git
synced 2024-11-10 14:41:50 +00:00
Fix error creating directories during update when the app is installed to a drive other than C: on Windows.
FileUtils::dirname() did not include the drive letter under Windows and the return value of dirname() was fed directly to mkpath(). When the drive letter is not specified, mkdir() assumes drive C: - this either fails if the user does not have access rights to drive C: or creates a directory in the wrong place. This commit changes FileUtils::dirname() to include the drive letter on Windows and adds a test.
This commit is contained in:
parent
f49c147c4f
commit
02fa638261
5 changed files with 43 additions and 2 deletions
|
@ -335,7 +335,14 @@ std::string FileUtils::dirname(const char* path)
|
|||
0 /* extension length */
|
||||
);
|
||||
|
||||
return std::string(dir);
|
||||
std::string result;
|
||||
if (drive[0])
|
||||
{
|
||||
result += std::string(drive);
|
||||
}
|
||||
result += dir;
|
||||
|
||||
return result;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
@ -84,7 +84,9 @@ class FileUtils
|
|||
/** Returns the file name part of a file path, including the extension. */
|
||||
static std::string fileName(const char* path);
|
||||
|
||||
/** Returns the directory part of a file path. */
|
||||
/** Returns the directory part of a file path.
|
||||
* On Windows this includes the drive letter, if present in @p path.
|
||||
*/
|
||||
static std::string dirname(const char* path);
|
||||
|
||||
/** Remove a directory and all of its contents. */
|
||||
|
|
|
@ -36,6 +36,12 @@ add_executable(TestUpdaterOptions
|
|||
target_link_libraries(TestUpdaterOptions
|
||||
updatershared
|
||||
)
|
||||
add_executable(TestFileUtils
|
||||
TestFileUtils.cpp
|
||||
)
|
||||
target_link_libraries(TestFileUtils
|
||||
updatershared
|
||||
)
|
||||
|
||||
if (APPLE)
|
||||
set_target_properties(TestUpdateScript PROPERTIES LINK_FLAGS "-framework Security -framework Cocoa")
|
||||
|
|
19
src/tests/TestFileUtils.cpp
Normal file
19
src/tests/TestFileUtils.cpp
Normal file
|
@ -0,0 +1,19 @@
|
|||
#include "TestFileUtils.h"
|
||||
|
||||
#include "FileUtils.h"
|
||||
#include "TestUtils.h"
|
||||
|
||||
void TestFileUtils::testDirName()
|
||||
{
|
||||
#ifdef PLATFORM_WINDOWS
|
||||
std::string dirName = FileUtils::dirname("E:/Some Dir/App.exe");
|
||||
TEST_COMPARE(dirName,"E:/Some Dir/");
|
||||
#endif
|
||||
}
|
||||
|
||||
int main(int,char**)
|
||||
{
|
||||
TestList<TestFileUtils> tests;
|
||||
tests.addTest(&TestFileUtils::testDirName);
|
||||
return TestUtils::runTest(tests);
|
||||
}
|
7
src/tests/TestFileUtils.h
Normal file
7
src/tests/TestFileUtils.h
Normal file
|
@ -0,0 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
class TestFileUtils
|
||||
{
|
||||
public:
|
||||
void testDirName();
|
||||
};
|
Loading…
Reference in a new issue