Ejemplo n.º 1
0
 void SetSrcFile(const std::string path) {
     src_file_ = path;
     if (!dest_dir_.empty()) {
         // Only uses device-provided name when user passed a directory.
         dest_file_ = adb_basename(path);
         SetLineMessage("generating");
     }
 }
int do_sync_pull(const char* rpath, const char* lpath, bool show_progress, int copy_attrs) {
    std::string error;
    int fd = adb_connect("sync:", &error);
    if (fd < 0) {
        fprintf(stderr,"error: %s\n", error.c_str());
        return 1;
    }

    unsigned mode, time;
    if (sync_readtime(fd, rpath, &time, &mode)) {
        return 1;
    }
    if (mode == 0) {
        fprintf(stderr,"remote object '%s' does not exist\n", rpath);
        return 1;
    }

    if (S_ISREG(mode) || S_ISLNK(mode) || S_ISCHR(mode) || S_ISBLK(mode)) {
        std::string path_holder;
        struct stat st;
        if (stat(lpath, &st) == 0) {
            if (S_ISDIR(st.st_mode)) {
                // If we're copying a remote file to a local directory,
                // we really want to copy to local_dir + "/" + basename(remote).
                path_holder = android::base::StringPrintf("%s/%s", lpath, adb_basename(rpath).c_str());
                lpath = path_holder.c_str();
            }
        }
        BEGIN();
        if (sync_recv(fd, rpath, lpath, show_progress)) {
            return 1;
        } else {
            if (copy_attrs && set_time_and_mode(lpath, time, mode)) {
                return 1;
            }
        }
    } else if(S_ISDIR(mode)) {
        BEGIN();
        if (copy_remote_dir_local(fd, rpath, lpath, copy_attrs)) {
            return 1;
        }
    } else {
        fprintf(stderr,"remote object '%s' not a file or directory\n", rpath);
        return 1;
    }
    END();
    sync_quit(fd);
    return 0;
}
int do_sync_push(const char* lpath, const char* rpath, bool show_progress) {
    std::string error;
    int fd = adb_connect("sync:", &error);
    if (fd < 0) {
        fprintf(stderr,"error: %s\n", error.c_str());
        return 1;
    }

    struct stat st;
    if (stat(lpath, &st)) {
        fprintf(stderr,"cannot stat '%s': %s\n", lpath, strerror(errno));
        sync_quit(fd);
        return 1;
    }

    if (S_ISDIR(st.st_mode)) {
        BEGIN();
        if (copy_local_dir_remote(fd, lpath, rpath, 0, 0)) {
            return 1;
        }
    } else {
        unsigned mode;
        if (sync_readmode(fd, rpath, &mode)) {
            return 1;
        }
        std::string path_holder;
        if ((mode != 0) && S_ISDIR(mode)) {
            // If we're copying a local file to a remote directory,
            // we really want to copy to remote_dir + "/" + local_filename.
            path_holder = android::base::StringPrintf("%s/%s", rpath, adb_basename(lpath).c_str());
            rpath = path_holder.c_str();
        }
        BEGIN();
        if (sync_send(fd, lpath, rpath, st.st_mtime, st.st_mode, show_progress)) {
            return 1;
        }
    }

    END();
    sync_quit(fd);
    return 0;
}
Ejemplo n.º 4
0
 void SetLineMessage(const std::string& action) {
     line_message_ = action + " " + adb_basename(dest_file_);
 }
TEST(adb_utils, adb_basename) {
  EXPECT_EQ("sh", adb_basename("/system/bin/sh"));
  EXPECT_EQ("sh", adb_basename("sh"));
}