Skip to content

Commit

Permalink
try fix automation-stack#31 on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
zh99998 committed Nov 7, 2016
1 parent ac2405a commit 710d526
Showing 1 changed file with 20 additions and 30 deletions.
50 changes: 20 additions & 30 deletions src/lib/sudoer.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,6 @@ class Sudoer {
return;
}
}
}


class SudoerUnix extends Sudoer {

constructor(options={}) {
super(options);
if (!this.options.name) { this.options.name = 'Electron'; }
}

async copy(source, target) {
let stats = await statAsync(source);
Expand Down Expand Up @@ -100,14 +91,24 @@ class SudoerUnix extends Sudoer {
return new Promise((resolve, reject)=> {
let readable = createReadStream(source);
readable.on("error", reject);
let writable = createWriteStream(target, {mode: mode});
let writable = createWriteStream(target, {defaultEncoding: 'binary', mode: mode});
writable.on("error", reject);
writable.on("close", resolve);
readable.pipe(writable);
})
}
}

}


class SudoerUnix extends Sudoer {

constructor(options={}) {
super(options);
if (!this.options.name) { this.options.name = 'Electron'; }
}

async remove(target) {
let self = this;
return new Promise(async (resolve, reject) => {
Expand Down Expand Up @@ -448,26 +449,15 @@ class SudoerWin32 extends Sudoer {
}

async prepare() {
let self = this;
return new Promise(async (resolve, reject) => {
if (self.binary) { return resolve(self.binary); }
// Copy applet to temporary directory
let target = join(this.tmpdir, 'elevate.exe');
if (!(await stat(target))) {
let copied = createWriteStream(target);
createReadStream(self.bundled).pipe(copied);
copied.on('close', () => {
self.binary = target;
return resolve(self.binary);
});
copied.on('error', (err) => {
return reject(err);
});
} else {
self.binary = target;
resolve(self.binary);
}
});
if (this.binary) { return this.binary }

// Copy applet to temporary directory
let target = join(this.tmpdir, 'elevate.exe');
if (!(await stat(target))) {
await copy(this.bundled, target)
}
this.binary = target;
return this.binary;
}

async exec(command, options={}) {
Expand Down

0 comments on commit 710d526

Please sign in to comment.