summaryrefslogtreecommitdiff
path: root/adb/adb_utils_test.cpp
diff options
context:
space:
mode:
authorSpencer Low <CompareAndSwap@gmail.com>2015-08-01 17:29:23 -0700
committerElliott Hughes <enh@google.com>2015-08-03 13:24:18 -0700
commit22191c30a63da7ca951281fffcb1fd59ae40dd54 (patch)
treeaab905c4e123fe0583af1f1e33db96642d9a8e50 /adb/adb_utils_test.cpp
parent8c61e0297c95a61bd3891704e7530ca1436a6421 (diff)
adb: fix mkdirs / adb pull with relative paths, fix win32 issues
Relative paths were being prefixed with OS_PATH_SEPARATOR on unix and win32 causing adb to incorrectly try to make directories at the root. Plus, absolute paths didn't work on win32 (C: got prefixed into \C:). This fix is to use dirname (available on win32 via mingw's crt) to do the messy parsing. I added a test for the relative path case. Change-Id: Ibb0a4a8ec7756351d252a4d267122ab18e182858 Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
Diffstat (limited to 'adb/adb_utils_test.cpp')
-rw-r--r--adb/adb_utils_test.cpp17
1 files changed, 13 insertions, 4 deletions
diff --git a/adb/adb_utils_test.cpp b/adb/adb_utils_test.cpp
index 9c9f85c7da..34b54e79ed 100644
--- a/adb/adb_utils_test.cpp
+++ b/adb/adb_utils_test.cpp
@@ -186,10 +186,19 @@ TEST(adb_utils, parse_host_and_port) {
EXPECT_FALSE(parse_host_and_port("1.2.3.4:65536", &canonical_address, &host, &port, &error));
}
+void test_mkdirs(const std::string basepath) {
+ EXPECT_TRUE(mkdirs(basepath));
+ EXPECT_NE(-1, adb_creat(basepath.c_str(), 0600));
+ EXPECT_FALSE(mkdirs(basepath + "/subdir/"));
+}
+
TEST(adb_utils, mkdirs) {
TemporaryDir td;
- std::string path = std::string(td.path) + "/dir/subdir/file";
- EXPECT_TRUE(mkdirs(path));
- EXPECT_NE(-1, adb_creat(path.c_str(), 0600));
- EXPECT_FALSE(mkdirs(path + "/subdir/"));
+
+ // Absolute paths.
+ test_mkdirs(std::string(td.path) + "/dir/subdir/file");
+
+ // Relative paths.
+ ASSERT_EQ(0, chdir(td.path)) << strerror(errno);
+ test_mkdirs(std::string("relative/subrel/file"));
}