Skip to content

Commit

Permalink
Improve sudoCommand helper function
Browse files Browse the repository at this point in the history
Don't take a parameter for a command to append.
Remove unnecessary escaping.
  • Loading branch information
timsueberkrueb committed Feb 17, 2018
1 parent 33673fc commit 8226804
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/adb.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const start = (password, sudo, callback) => {
stop(err => {
var cmd="";
if (utils.needRoot() && sudo)
cmd += utils.sudoCommand(password, "");
cmd += utils.sudoCommand(password);
cmd += adb + " -P " + PORT + " start-server";
utils.platfromToolsExecAsar("adb", (platfromToolsExecAsar) => {
platfromToolsExecAsar.exec(cmd, (c, r, e) => {
Expand Down
10 changes: 5 additions & 5 deletions src/fastboot.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ var waitForDevice = (password, callback) => {
utils.log.debug("fastboot: wait for device");
var cmd = "";
if (utils.needRoot())
cmd += utils.sudoCommand(password, "");
cmd += utils.sudoCommand(password);
cmd += "fastboot" + " devices";
var stop;
utils.platfromToolsExecAsar("fastboot", (asarExec) => {
Expand Down Expand Up @@ -106,7 +106,7 @@ var flash = (images, callback, password) => {
var cmd = "";
images.forEach((image, l) => {
if (utils.needRoot())
cmd += utils.sudoCommand(password, "");
cmd += utils.sudoCommand(password);
cmd += "fastboot" + " flash " + image.type + " \"" + path.join(image.path, path.basename(image.url)) + "\"";
if (l !== images.length - 1)
cmd += " && "
Expand Down Expand Up @@ -135,7 +135,7 @@ image object format
var boot = (image, password, callback) => {
var cmd="";
if (utils.needRoot())
cmd += utils.sudoCommand(password, "");
cmd += utils.sudoCommand(password);
cmd += "fastboot" + " boot \"" + path.join(image.path, path.basename(image.url)) + "\"";
utils.platfromToolsExecAsar("fastboot", (asarExec) => {
asarExec.exec(cmd, (c, r, e) => {
Expand All @@ -153,7 +153,7 @@ var format = (partitions, password, callback) => {
var cmd="";
partitions.forEach((partition, l) => {
if (utils.needRoot())
cmd += utils.sudoCommand(password, "");
cmd += utils.sudoCommand(password);
cmd += "fastboot" + " format " + partition;
if (l !== partitions.length - 1)
cmd += " && "
Expand All @@ -174,7 +174,7 @@ args; array, string, function
var oem = (command, password, callback) => {
var cmd="";
if (utils.needRoot())
cmd += utils.sudoCommand(password, "");
cmd += utils.sudoCommand(password);
cmd += "fastboot" + " oem " + command;
utils.platfromToolsExecAsar("fastboot", (asarExec) => {
asarExec.exec(cmd, (c, r, e) => {
Expand Down
6 changes: 3 additions & 3 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ var die = (e) => {
process.exit(1);
}

var sudoCommand = (password, cmd) => {
return "echo \'" + password.replace(/\'/g, "'\\''") + "\' | sudo -S " + cmd;
var sudoCommand = (password) => {
return "echo '" + password.replace(/\'/g, "'\\''") + "' | sudo -S ";
}

var checkPassword = (password, callback) => {
Expand All @@ -141,7 +141,7 @@ var checkPassword = (password, callback) => {
return;
}
log.debug("checking password")
exec(sudoCommand(password, "echo correct"), (err, output) => {
exec(sudoCommand(password) + "echo correct", (err, output) => {
if(err){
if (err.message.includes("incorrect password")) {
log.debug("incorrect password")
Expand Down

0 comments on commit 8226804

Please sign in to comment.