refactor: address code review comments from #1366 (#1390)

See: https://github.com/resin-io/etcher/pull/1366
Signed-off-by: Juan Cruz Viotti <jviotti@openmailbox.org>
This commit is contained in:
Juan Cruz Viotti 2017-05-09 19:33:45 -04:00 committed by GitHub
parent efa7f986a4
commit 7ddc5d525c
7 changed files with 20 additions and 11 deletions

View File

@ -156,6 +156,7 @@ TARGET_ARCH_DEBIAN = $(shell ./scripts/build/architecture-convert.sh -r $(TARGET
PRODUCT_NAME = etcher
APPLICATION_NAME_LOWERCASE = $(shell echo $(APPLICATION_NAME) | tr A-Z a-z)
APPLICATION_VERSION_DEBIAN = $(shell echo $(APPLICATION_VERSION) | tr "-" "~")
CPRF = cp -RLf
# ---------------------------------------------------------------------
# Rules
@ -180,26 +181,22 @@ $(BUILD_OUTPUT_DIRECTORY): | $(BUILD_DIRECTORY)
$(BUILD_DIRECTORY)/electron-$(TARGET_PLATFORM)-$(TARGET_ARCH)-dependencies: package.json npm-shrinkwrap.json \
| $(BUILD_DIRECTORY)
mkdir $@
cp -rf src $@
./scripts/build/dependencies-npm.sh -p \
-r "$(TARGET_ARCH)" \
-v "$(ELECTRON_VERSION)" \
-x $@ \
-t electron \
-s "$(TARGET_PLATFORM)"
rm -rf $@/src
$(BUILD_DIRECTORY)/node-$(TARGET_PLATFORM)-$(TARGET_ARCH)-dependencies: package.json npm-shrinkwrap.json \
| $(BUILD_DIRECTORY)
mkdir $@
cp -rf src $@
./scripts/build/dependencies-npm.sh -p -f \
-r "$(TARGET_ARCH)" \
-v "$(NODE_VERSION)" \
-x $@ \
-t node \
-s "$(TARGET_PLATFORM)"
rm -rf $@/src
$(BUILD_DIRECTORY)/electron-$(TARGET_PLATFORM)-$(APPLICATION_VERSION)-$(TARGET_ARCH)-app: \
$(BUILD_DIRECTORY)/electron-$(TARGET_PLATFORM)-$(TARGET_ARCH)-dependencies \
@ -207,7 +204,7 @@ $(BUILD_DIRECTORY)/electron-$(TARGET_PLATFORM)-$(APPLICATION_VERSION)-$(TARGET_A
./scripts/build/electron-create-resources-app.sh -s . -o $@ \
-v $(APPLICATION_VERSION) \
-f "$(APPLICATION_FILES)"
cp -RLf $</* $@
$(CPRF) $</* $@
ifdef ANALYTICS_SENTRY_TOKEN
./scripts/build/jq-insert.sh \
@ -244,8 +241,8 @@ $(BUILD_DIRECTORY)/$(APPLICATION_NAME)-cli-$(TARGET_PLATFORM)-$(APPLICATION_VERS
| $(BUILD_DIRECTORY)
mkdir $@
cp $(word 1,$^) $@
cp $(word 2,$^) $@
cp -rf $(word 3,$^)/* $@
$(CPRF) $(word 2,$^) $@
$(CPRF) $(word 3,$^)/* $@
$(BUILD_DIRECTORY)/$(APPLICATION_NAME)-cli-$(TARGET_PLATFORM)-$(APPLICATION_VERSION)-$(TARGET_ARCH).js: \
$(BUILD_DIRECTORY)/$(APPLICATION_NAME)-cli-$(TARGET_PLATFORM)-$(APPLICATION_VERSION)-$(TARGET_ARCH)-app \

View File

@ -11,7 +11,7 @@
[ 'OS=="win"', {
"sources": [
"src/utils/v8utils.cpp",
"src/os/elevate.cpp",
"src/os/win32/elevate.cpp",
"src/elevator_init.cpp",
],
"libraries": [

View File

@ -28,7 +28,7 @@ const bindings = require('bindings');
* @returns {Object} native module
*
* @example
* const elevator = bindings.load('elevator');
* const elevator = nativeModule.load('elevator');
*/
exports.load = (moduleName) => {
return bindings({

View File

@ -17,7 +17,7 @@
'use strict';
const os = require('os');
const bindings = require('./bindings');
const nativeModule = require('./native-module');
const Bluebird = require('bluebird');
const childProcess = Bluebird.promisifyAll(require('child_process'));
const sudoPrompt = Bluebird.promisifyAll(require('sudo-prompt'));
@ -146,7 +146,7 @@ exports.elevateCommand = (command, options) => {
const prefixedCommand = _.concat(exports.getEnvironmentCommandPrefix(options.environment), command);
if (os.platform() === 'win32') {
const elevator = Bluebird.promisifyAll(bindings.load('elevator'));
const elevator = Bluebird.promisifyAll(nativeModule.load('elevator'));
return elevator.elevateAsync(_.concat([
'cmd.exe',
'/c'

View File

@ -133,6 +133,11 @@ if [ -n "$ARGV_PREFIX" ]; then
cp "$PWD/binding.gyp" "$ARGV_PREFIX/binding.gyp"
fi
# Handle native code, if any
if [ -d "$PWD/src" ]; then
cp -RLf "$PWD/src" "$ARGV_PREFIX/src"
fi
pushd "$ARGV_PREFIX"
run_install
popd
@ -140,6 +145,7 @@ if [ -n "$ARGV_PREFIX" ]; then
rm -f "$ARGV_PREFIX/package.json"
rm -f "$ARGV_PREFIX/npm-shrinkwrap.json"
rm -f "$ARGV_PREFIX/binding.gyp"
rm -rf "$ARGV_PREFIX/src"
else
run_install
fi

View File

@ -17,6 +17,8 @@
* limitations under the License.
*/
#ifdef _WIN32
// Fix winsock.h redefinition errors
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
@ -27,6 +29,8 @@
#include <windows.h>
#include <shellapi.h>
#endif
#include <algorithm>
#include <iterator>
#include <sstream>

View File

@ -86,6 +86,8 @@ etcher::ELEVATE_RESULT etcher::Elevate(const std::string &command,
if (!executeResult) {
DWORD executeError = GetLastError();
// We map Windows error codes to our own enum class
// so we can normalize all Windows error handling mechanisms.
switch (executeError) {
case ERROR_FILE_NOT_FOUND:
return etcher::ELEVATE_RESULT::ELEVATE_FILE_NOT_FOUND;