Skip to content

Commit

Permalink
Support paths containing spaces on Windows
Browse files Browse the repository at this point in the history
Quote the arguments of "adb push" to support paths which contain spaces
on Windows.

Fixes <Genymobile#288>.
  • Loading branch information
rom1v committed Oct 4, 2018
1 parent ff4430b commit 8875955
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 10 deletions.
47 changes: 37 additions & 10 deletions app/src/command.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "common.h"
#include "log.h"
#include "str_util.h"

static const char *adb_command;

Expand Down Expand Up @@ -89,23 +90,49 @@ process_t adb_reverse_remove(const char *serial, const char *device_socket_name)
}

process_t adb_push(const char *serial, const char *local, const char *remote) {
#ifdef __WINDOWS__
// Windows will parse the string, so the paths must be quoted
// (see sys/win/command.c)
local = strquote(local);
if (!local) {
return PROCESS_NONE;
}
remote = strquote(remote);
if (!remote) {
free((void *) local);
return PROCESS_NONE;
}
#endif

const char *const adb_cmd[] = {"push", local, remote};
return adb_execute(serial, adb_cmd, ARRAY_LEN(adb_cmd));
process_t proc = adb_execute(serial, adb_cmd, ARRAY_LEN(adb_cmd));

#ifdef __WINDOWS__
free((void *) remote);
free((void *) local);
#endif

return proc;
}

process_t adb_install(const char *serial, const char *local) {
#ifdef __WINDOWS__
// Windows will parse the string, so the local name must be quoted (see sys/win/command.c)
size_t len = strlen(local);
char quoted[len + 3];
memcpy(&quoted[1], local, len);
quoted[0] = '"';
quoted[len + 1] = '"';
quoted[len + 2] = '\0';
local = quoted;
// Windows will parse the string, so the local name must be quoted
// (see sys/win/command.c)
local = strquote(local);
if (!local) {
return PROCESS_NONE;
}
#endif

const char *const adb_cmd[] = {"install", "-r", local};
return adb_execute(serial, adb_cmd, ARRAY_LEN(adb_cmd));
process_t proc = adb_execute(serial, adb_cmd, ARRAY_LEN(adb_cmd));

#ifdef __WINDOWS__
free((void *) local);
#endif

return proc;
}

process_t adb_remove_path(const char *serial, const char *path) {
Expand Down
16 changes: 16 additions & 0 deletions app/src/str_util.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#include "str_util.h"

#include <stdlib.h>
#include <string.h>

size_t xstrncpy(char *dest, const char *src, size_t n) {
size_t i;
for (i = 0; i < n - 1 && src[i] != '\0'; ++i)
Expand Down Expand Up @@ -31,3 +34,16 @@ size_t xstrjoin(char *dst, const char *const tokens[], char sep, size_t n) {
dst[n - 1] = '\0';
return n;
}

char *strquote(const char *src) {
size_t len = strlen(src);
char *quoted = malloc(len + 3);
if (!quoted) {
return NULL;
}
memcpy(&quoted[1], src, len);
quoted[0] = '"';
quoted[len + 1] = '"';
quoted[len + 2] = '\0';
return quoted;
}
4 changes: 4 additions & 0 deletions app/src/str_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@ size_t xstrncpy(char *dest, const char *src, size_t n);
// occurred, or n if truncated
size_t xstrjoin(char *dst, const char *const tokens[], char sep, size_t n);

// quote a string
// returns the new allocated string, to be freed by the caller
char *strquote(const char *src);

#endif

0 comments on commit 8875955

Please sign in to comment.