Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7b84c9bf authored by Josh Gao's avatar Josh Gao Committed by Android (Google) Code Review
Browse files

Merge changes from topic 'adb_cherrypick' into nyc-dev

* changes:
  adb: sysdeps_test: improve smoke test.
  adb: check for an error response from adbd between each write.
  adbd: restore the old error handling behavior.
  adb: change unsigned to uint32_t in sync struct definitions.
  adb: detect when the client disconnects in wait-for-device.
  adb: make fdevent_test, socket_test compile on Windows.
  adb: add fd exhaustion test, fix errno reporting in sysdeps_win32.
  adb: move win32 fd base to 2048, fix fd allocation.
  adb: don't emulate fdevent or socketpair on Windows.
  adb: fix clang-format for access modifier dedent.
  Add missing liblog dependency
  adb: sysdeps_win32: actually change ExitThread to _endthreadex.
  adb: make adb_thread_func_t return void, add adb_thread_exit.
  adb: redact reference to secret internal time machine.
  adb: mkdirs fixes
  adb: sysdeps: add support for joining threads.
  adb: allow wine's output for sysdeps_win32 strerror test.
  adb: setsid() for adb host server.
  adb: make ctrl-c when spawning a daemon not kill the daemon.
  adb: fix mkdirs test.
parents 2f9cd05c fa3e0bc6
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@ BasedOnStyle: Google
AllowShortBlocksOnASingleLine: false
AllowShortFunctionsOnASingleLine: false

AccessModifierOffset: -2
ColumnLimit: 100
CommentPragmas: NOLINT:.*
DerivePointerAlignment: false
+5 −11
Original line number Diff line number Diff line
@@ -50,6 +50,7 @@ LIBADB_SRC_FILES := \
    adb_listeners.cpp \
    adb_trace.cpp \
    adb_utils.cpp \
    fdevent.cpp \
    sockets.cpp \
    transport.cpp \
    transport_local.cpp \
@@ -58,6 +59,9 @@ LIBADB_SRC_FILES := \
LIBADB_TEST_SRCS := \
    adb_io_test.cpp \
    adb_utils_test.cpp \
    fdevent_test.cpp \
    socket_test.cpp \
    sysdeps_test.cpp \
    transport_test.cpp \

LIBADB_CFLAGS := \
@@ -74,12 +78,10 @@ LIBADB_windows_CFLAGS := \
    $(ADB_COMMON_windows_CFLAGS) \

LIBADB_darwin_SRC_FILES := \
    fdevent.cpp \
    get_my_path_darwin.cpp \
    usb_osx.cpp \

LIBADB_linux_SRC_FILES := \
    fdevent.cpp \
    get_my_path_linux.cpp \
    usb_linux.cpp \

@@ -87,14 +89,6 @@ LIBADB_windows_SRC_FILES := \
    sysdeps_win32.cpp \
    usb_windows.cpp \

LIBADB_TEST_linux_SRCS := \
    fdevent_test.cpp \
    socket_test.cpp \

LIBADB_TEST_darwin_SRCS := \
    fdevent_test.cpp \
    socket_test.cpp \

LIBADB_TEST_windows_SRCS := \
    sysdeps_win32_test.cpp \

@@ -157,7 +151,7 @@ LOCAL_SRC_FILES := \

LOCAL_SANITIZE := $(adb_target_sanitize)
LOCAL_STATIC_LIBRARIES := libadbd
LOCAL_SHARED_LIBRARIES := libbase libcutils
LOCAL_SHARED_LIBRARIES := liblog libbase libcutils
include $(BUILD_NATIVE_TEST)

# libdiagnose_usb
+0 −2
Original line number Diff line number Diff line
@@ -883,8 +883,6 @@ int launch_server(int server_port)
            fprintf(stderr, "ADB server didn't ACK\n" );
            return -1;
        }

        setsid();
    }
#endif /* !defined(_WIN32) */
    return 0;
+8 −7
Original line number Diff line number Diff line
@@ -134,7 +134,7 @@ std::string adb_dirname(const std::string& path) {
  return result;
}

// Given a relative or absolute filepath, create the parent directory hierarchy
// Given a relative or absolute filepath, create the directory hierarchy
// as needed. Returns true if the hierarchy is/was setup.
bool mkdirs(const std::string& path) {
  // TODO: all the callers do unlink && mkdirs && adb_creat ---
@@ -157,12 +157,12 @@ bool mkdirs(const std::string& path) {
    return true;
  }

  const std::string parent(adb_dirname(path));

  // If dirname returned the same path as what we passed in, don't go recursive.
  // This can happen on Windows when walking up the directory hierarchy and not
  // finding anything that already exists (unlike POSIX that will eventually
  // find . or /).
  const std::string parent(adb_dirname(path));

  if (parent == path) {
    errno = ENOENT;
    return false;
@@ -174,14 +174,14 @@ bool mkdirs(const std::string& path) {
  }

  // Now that the parent directory hierarchy of 'path' has been ensured,
  // create parent itself.
  // create path itself.
  if (adb_mkdir(path, 0775) == -1) {
    // Can't just check for errno == EEXIST because it might be a file that
    // exists.
    const int saved_errno = errno;
    if (directory_exists(parent)) {
    // If someone else created the directory, that is ok.
    if (directory_exists(path)) {
      return true;
    }
    // There might be a pre-existing file at 'path', or there might have been some other error.
    errno = saved_errno;
    return false;
  }
@@ -213,6 +213,7 @@ std::string perror_str(const char* msg) {
}

#if !defined(_WIN32)
// Windows version provided in sysdeps_win32.cpp
bool set_file_block_mode(int fd, bool block) {
    int flags = fcntl(fd, F_GETFL, 0);
    if (flags == -1) {
+10 −4
Original line number Diff line number Diff line
@@ -112,20 +112,26 @@ TEST(adb_utils, adb_dirname) {
}

void test_mkdirs(const std::string basepath) {
  // Test creating a directory hierarchy.
  EXPECT_TRUE(mkdirs(basepath));
  EXPECT_NE(-1, adb_creat(basepath.c_str(), 0600));
  EXPECT_FALSE(mkdirs(basepath + "/subdir/"));
  // Test finding an existing directory hierarchy.
  EXPECT_TRUE(mkdirs(basepath));
  const std::string filepath = basepath + "/file";
  // Verify that the hierarchy was created by trying to create a file in it.
  EXPECT_NE(-1, adb_creat(filepath.c_str(), 0600));
  // If a file exists where we want a directory, the operation should fail.
  EXPECT_FALSE(mkdirs(filepath));
}

TEST(adb_utils, mkdirs) {
  TemporaryDir td;

  // Absolute paths.
  test_mkdirs(std::string(td.path) + "/dir/subdir/file");
  test_mkdirs(std::string(td.path) + "/dir/subdir");

  // Relative paths.
  ASSERT_EQ(0, chdir(td.path)) << strerror(errno);
  test_mkdirs(std::string("relative/subrel/file"));
  test_mkdirs(std::string("relative/subrel"));
}

#if !defined(_WIN32)
Loading