Loading adb/adb_io_test.cpp +1 −24 Original line number Diff line number Diff line Loading @@ -28,30 +28,7 @@ #include <string> #include "base/file.h" class TemporaryFile { public: TemporaryFile() { init("/data/local/tmp"); if (fd == -1) { init("/tmp"); } } ~TemporaryFile() { close(fd); unlink(filename); } int fd; char filename[1024]; private: void init(const char* tmp_dir) { snprintf(filename, sizeof(filename), "%s/TemporaryFile-XXXXXX", tmp_dir); fd = mkstemp(filename); } }; #include "base/test_utils.h" TEST(io, ReadFdExactly_whole) { const char expected[] = "Foobar"; Loading adb/adb_utils.cpp +5 −16 Original line number Diff line number Diff line Loading @@ -72,24 +72,13 @@ std::string escape_arg(const std::string& s) { return result; } int mkdirs(const std::string& path) { // TODO: rewrite this function and merge it with the *other* mkdirs in adb. std::unique_ptr<char> path_rw(strdup(path.c_str())); int ret; char* x = path_rw.get() + 1; for(;;) { x = const_cast<char*>(adb_dirstart(x)); if(x == 0) return 0; *x = 0; ret = adb_mkdir(path_rw.get(), 0775); *x = OS_PATH_SEPARATOR; if((ret < 0) && (errno != EEXIST)) { return ret; } x++; } return 0; bool mkdirs(const std::string& path) { for (size_t i = adb_dirstart(path, 1); i != std::string::npos; i = adb_dirstart(path, i + 1)) { if (adb_mkdir(path.substr(0, i), 0775) == -1 && errno != EEXIST) { return false; } } return true; } void dump_hex(const void* data, size_t byte_count) { Loading adb/adb_utils.h +1 −1 Original line number Diff line number Diff line Loading @@ -22,7 +22,7 @@ bool getcwd(std::string* cwd); bool directory_exists(const std::string& path); int mkdirs(const std::string& path); bool mkdirs(const std::string& path); std::string escape_arg(const std::string& s); Loading adb/adb_utils_test.cpp +15 −0 Original line number Diff line number Diff line Loading @@ -18,6 +18,13 @@ #include <gtest/gtest.h> #include <stdlib.h> #include <string.h> #include "sysdeps.h" #include <base/test_utils.h> TEST(adb_utils, directory_exists) { ASSERT_TRUE(directory_exists("/proc")); ASSERT_FALSE(directory_exists("/proc/self")); // Symbolic link. Loading Loading @@ -132,3 +139,11 @@ TEST(adb_utils, parse_host_and_port) { EXPECT_FALSE(parse_host_and_port("1.2.3.4:0", &canonical_address, &host, &port, &error)); EXPECT_FALSE(parse_host_and_port("1.2.3.4:65536", &canonical_address, &host, &port, &error)); } TEST(adb_utils, mkdirs) { TemporaryDir td; EXPECT_TRUE(mkdirs(std::string(td.path) + "/dir/subdir/file")); std::string file = std::string(td.path) + "/file"; adb_creat(file.c_str(), 0600); EXPECT_FALSE(mkdirs(file + "/subdir/")); } adb/commandline.cpp +7 −7 Original line number Diff line number Diff line Loading @@ -859,7 +859,7 @@ static std::string find_product_out_path(const char* hint) { // If there are any slashes in it, assume it's a relative path; // make it absolute. if (adb_dirstart(hint) != nullptr) { if (adb_dirstart(hint) != std::string::npos) { std::string cwd; if (!getcwd(&cwd)) { fprintf(stderr, "adb: getcwd failed: %s\n", strerror(errno)); Loading Loading @@ -1467,15 +1467,15 @@ static int delete_file(TransportType transport, const char* serial, char* filena return send_shell_command(transport, serial, cmd); } static const char* get_basename(const char* filename) static const char* get_basename(const std::string& filename) { const char* basename = adb_dirstop(filename); if (basename) { basename++; return basename; size_t base = adb_dirstop(filename); if (base != std::string::npos) { ++base; } else { return filename; base = 0; } return filename.c_str() + base; } static int install_app(TransportType transport, const char* serial, int argc, const char** argv) { Loading Loading
adb/adb_io_test.cpp +1 −24 Original line number Diff line number Diff line Loading @@ -28,30 +28,7 @@ #include <string> #include "base/file.h" class TemporaryFile { public: TemporaryFile() { init("/data/local/tmp"); if (fd == -1) { init("/tmp"); } } ~TemporaryFile() { close(fd); unlink(filename); } int fd; char filename[1024]; private: void init(const char* tmp_dir) { snprintf(filename, sizeof(filename), "%s/TemporaryFile-XXXXXX", tmp_dir); fd = mkstemp(filename); } }; #include "base/test_utils.h" TEST(io, ReadFdExactly_whole) { const char expected[] = "Foobar"; Loading
adb/adb_utils.cpp +5 −16 Original line number Diff line number Diff line Loading @@ -72,24 +72,13 @@ std::string escape_arg(const std::string& s) { return result; } int mkdirs(const std::string& path) { // TODO: rewrite this function and merge it with the *other* mkdirs in adb. std::unique_ptr<char> path_rw(strdup(path.c_str())); int ret; char* x = path_rw.get() + 1; for(;;) { x = const_cast<char*>(adb_dirstart(x)); if(x == 0) return 0; *x = 0; ret = adb_mkdir(path_rw.get(), 0775); *x = OS_PATH_SEPARATOR; if((ret < 0) && (errno != EEXIST)) { return ret; } x++; } return 0; bool mkdirs(const std::string& path) { for (size_t i = adb_dirstart(path, 1); i != std::string::npos; i = adb_dirstart(path, i + 1)) { if (adb_mkdir(path.substr(0, i), 0775) == -1 && errno != EEXIST) { return false; } } return true; } void dump_hex(const void* data, size_t byte_count) { Loading
adb/adb_utils.h +1 −1 Original line number Diff line number Diff line Loading @@ -22,7 +22,7 @@ bool getcwd(std::string* cwd); bool directory_exists(const std::string& path); int mkdirs(const std::string& path); bool mkdirs(const std::string& path); std::string escape_arg(const std::string& s); Loading
adb/adb_utils_test.cpp +15 −0 Original line number Diff line number Diff line Loading @@ -18,6 +18,13 @@ #include <gtest/gtest.h> #include <stdlib.h> #include <string.h> #include "sysdeps.h" #include <base/test_utils.h> TEST(adb_utils, directory_exists) { ASSERT_TRUE(directory_exists("/proc")); ASSERT_FALSE(directory_exists("/proc/self")); // Symbolic link. Loading Loading @@ -132,3 +139,11 @@ TEST(adb_utils, parse_host_and_port) { EXPECT_FALSE(parse_host_and_port("1.2.3.4:0", &canonical_address, &host, &port, &error)); EXPECT_FALSE(parse_host_and_port("1.2.3.4:65536", &canonical_address, &host, &port, &error)); } TEST(adb_utils, mkdirs) { TemporaryDir td; EXPECT_TRUE(mkdirs(std::string(td.path) + "/dir/subdir/file")); std::string file = std::string(td.path) + "/file"; adb_creat(file.c_str(), 0600); EXPECT_FALSE(mkdirs(file + "/subdir/")); }
adb/commandline.cpp +7 −7 Original line number Diff line number Diff line Loading @@ -859,7 +859,7 @@ static std::string find_product_out_path(const char* hint) { // If there are any slashes in it, assume it's a relative path; // make it absolute. if (adb_dirstart(hint) != nullptr) { if (adb_dirstart(hint) != std::string::npos) { std::string cwd; if (!getcwd(&cwd)) { fprintf(stderr, "adb: getcwd failed: %s\n", strerror(errno)); Loading Loading @@ -1467,15 +1467,15 @@ static int delete_file(TransportType transport, const char* serial, char* filena return send_shell_command(transport, serial, cmd); } static const char* get_basename(const char* filename) static const char* get_basename(const std::string& filename) { const char* basename = adb_dirstop(filename); if (basename) { basename++; return basename; size_t base = adb_dirstop(filename); if (base != std::string::npos) { ++base; } else { return filename; base = 0; } return filename.c_str() + base; } static int install_app(TransportType transport, const char* serial, int argc, const char** argv) { Loading