Merge changes I70c94c4b,Ifd8769ed
* changes: adb: make mkdirs/secure_mkdirs do what they say. adb: remove use of mkdirs from `adb backup`.
This commit is contained in:
commit
11d18f1491
4 changed files with 15 additions and 12 deletions
|
|
@ -134,9 +134,7 @@ bool mkdirs(const std::string& path) {
|
||||||
// - Recursive, so it uses stack space relative to number of directory
|
// - Recursive, so it uses stack space relative to number of directory
|
||||||
// components.
|
// components.
|
||||||
|
|
||||||
const std::string parent(adb_dirname(path));
|
if (directory_exists(path)) {
|
||||||
|
|
||||||
if (directory_exists(parent)) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -144,19 +142,21 @@ bool mkdirs(const std::string& path) {
|
||||||
// This can happen on Windows when walking up the directory hierarchy and not
|
// This can happen on Windows when walking up the directory hierarchy and not
|
||||||
// finding anything that already exists (unlike POSIX that will eventually
|
// finding anything that already exists (unlike POSIX that will eventually
|
||||||
// find . or /).
|
// find . or /).
|
||||||
|
const std::string parent(adb_dirname(path));
|
||||||
|
|
||||||
if (parent == path) {
|
if (parent == path) {
|
||||||
errno = ENOENT;
|
errno = ENOENT;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recursively make parent directories of 'parent'.
|
// Recursively make parent directories of 'path'.
|
||||||
if (!mkdirs(parent)) {
|
if (!mkdirs(parent)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now that the parent directory hierarchy of 'parent' has been ensured,
|
// Now that the parent directory hierarchy of 'path' has been ensured,
|
||||||
// create parent itself.
|
// create parent itself.
|
||||||
if (adb_mkdir(parent, 0775) == -1) {
|
if (adb_mkdir(path, 0775) == -1) {
|
||||||
// Can't just check for errno == EEXIST because it might be a file that
|
// Can't just check for errno == EEXIST because it might be a file that
|
||||||
// exists.
|
// exists.
|
||||||
const int saved_errno = errno;
|
const int saved_errno = errno;
|
||||||
|
|
|
||||||
|
|
@ -1074,7 +1074,6 @@ static int backup(int argc, const char** argv) {
|
||||||
if (argc < 2) return usage();
|
if (argc < 2) return usage();
|
||||||
|
|
||||||
adb_unlink(filename);
|
adb_unlink(filename);
|
||||||
mkdirs(filename);
|
|
||||||
int outFd = adb_creat(filename, 0640);
|
int outFd = adb_creat(filename, 0640);
|
||||||
if (outFd < 0) {
|
if (outFd < 0) {
|
||||||
fprintf(stderr, "adb: unable to open file %s\n", filename);
|
fprintf(stderr, "adb: unable to open file %s\n", filename);
|
||||||
|
|
|
||||||
|
|
@ -392,7 +392,12 @@ static bool sync_recv(SyncConnection& sc, const char* rpath, const char* lpath)
|
||||||
if (!sc.SendRequest(ID_RECV, rpath)) return false;
|
if (!sc.SendRequest(ID_RECV, rpath)) return false;
|
||||||
|
|
||||||
adb_unlink(lpath);
|
adb_unlink(lpath);
|
||||||
mkdirs(lpath);
|
if (!mkdirs(adb_dirname(lpath))) {
|
||||||
|
sc.Error("failed to create parent directory '%s': %s",
|
||||||
|
adb_dirname(lpath).c_str(), strerror(errno));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
int lfd = adb_creat(lpath, 0644);
|
int lfd = adb_creat(lpath, 0644);
|
||||||
if (lfd < 0) {
|
if (lfd < 0) {
|
||||||
sc.Error("cannot create '%s': %s", lpath, strerror(errno));
|
sc.Error("cannot create '%s': %s", lpath, strerror(errno));
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,7 @@
|
||||||
|
|
||||||
#include "adb.h"
|
#include "adb.h"
|
||||||
#include "adb_io.h"
|
#include "adb_io.h"
|
||||||
|
#include "adb_utils.h"
|
||||||
#include "private/android_filesystem_config.h"
|
#include "private/android_filesystem_config.h"
|
||||||
|
|
||||||
#include <base/stringprintf.h>
|
#include <base/stringprintf.h>
|
||||||
|
|
@ -53,8 +54,6 @@ static bool secure_mkdirs(const std::string& path) {
|
||||||
if (path[0] != '/') return false;
|
if (path[0] != '/') return false;
|
||||||
|
|
||||||
std::vector<std::string> path_components = android::base::Split(path, "/");
|
std::vector<std::string> path_components = android::base::Split(path, "/");
|
||||||
path_components.pop_back(); // For "/system/bin/sh", only create "/system/bin".
|
|
||||||
|
|
||||||
std::string partial_path;
|
std::string partial_path;
|
||||||
for (const auto& path_component : path_components) {
|
for (const auto& path_component : path_components) {
|
||||||
if (partial_path.back() != OS_PATH_SEPARATOR) partial_path += OS_PATH_SEPARATOR;
|
if (partial_path.back() != OS_PATH_SEPARATOR) partial_path += OS_PATH_SEPARATOR;
|
||||||
|
|
@ -149,7 +148,7 @@ static bool handle_send_file(int s, const char* path, uid_t uid,
|
||||||
|
|
||||||
int fd = adb_open_mode(path, O_WRONLY | O_CREAT | O_EXCL | O_CLOEXEC, mode);
|
int fd = adb_open_mode(path, O_WRONLY | O_CREAT | O_EXCL | O_CLOEXEC, mode);
|
||||||
if (fd < 0 && errno == ENOENT) {
|
if (fd < 0 && errno == ENOENT) {
|
||||||
if (!secure_mkdirs(path)) {
|
if (!secure_mkdirs(adb_dirname(path))) {
|
||||||
SendSyncFailErrno(s, "secure_mkdirs failed");
|
SendSyncFailErrno(s, "secure_mkdirs failed");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
@ -244,7 +243,7 @@ static bool handle_send_link(int s, const std::string& path, std::vector<char>&
|
||||||
|
|
||||||
ret = symlink(&buffer[0], path.c_str());
|
ret = symlink(&buffer[0], path.c_str());
|
||||||
if (ret && errno == ENOENT) {
|
if (ret && errno == ENOENT) {
|
||||||
if (!secure_mkdirs(path)) {
|
if (!secure_mkdirs(adb_dirname(path))) {
|
||||||
SendSyncFailErrno(s, "secure_mkdirs failed");
|
SendSyncFailErrno(s, "secure_mkdirs failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue