Skip to content
Browse files

fixed installation issue

  • Loading branch information...
1 parent 7063855 commit d05b14c3a7b79610cf47c1065ff0ed6eb1535fbd @fent fent committed Sep 8, 2011
Showing with 32 additions and 25 deletions.
  1. +1 −1 package.json
  2. +14 −10 scripts/download.coffee
  3. +17 −14 scripts/download.js
View
2 package.json
@@ -2,7 +2,7 @@
"name": "youtube-dl",
"description": "youtube-dl driver for node",
"keywords": ["youtube", "download"],
- "version": "1.1.0",
+ "version": "1.1.1",
"homepage": "https://github.com/fent/node-youtube-dl",
"repository": {
"type": "git",
View
24 scripts/download.coffee
@@ -12,6 +12,18 @@ filepath = folder + filename
symlink = path.dirname(process.env._) + filename
+# removes symlink only if it exists
+removeLink = ->
+ linkExists = (try
+ fs.readlinkSync symlink
+ true
+ catch err
+ false
+ )
+ if linkExists
+ fs.unlinkSync symlink
+
+
# download youtube-dl
switch process.env.npm_lifecycle_event
when 'preinstall', 'update'
@@ -29,15 +41,7 @@ switch process.env.npm_lifecycle_event
fs.mkdirSync folder, 0744
# remove symlink if it exists
-
- linkExists = (try
- fs.readlinkSync symlink
- true
- catch err
- false
- )
- if linkExists
- fs.unlinkSync symlink
+ removeLink()
# write, chdmod, and symlink file when finished
fs.writeFileSync filepath, content
@@ -49,4 +53,4 @@ switch process.env.npm_lifecycle_event
when 'preuninstall'
# remove symlink
- fs.unlinkSync symlink
+ removeLink()
View
31 scripts/download.js
@@ -1,5 +1,5 @@
(function() {
- var exec, filename, filepath, folder, fs, https, path, symlink;
+ var exec, filename, filepath, folder, fs, https, path, removeLink, symlink;
fs = require('fs');
path = require('path');
https = require('https');
@@ -8,6 +8,20 @@
filename = '/youtube-dl';
filepath = folder + filename;
symlink = path.dirname(process.env._) + filename;
+ removeLink = function() {
+ var linkExists;
+ linkExists = ((function() {
+ try {
+ fs.readlinkSync(symlink);
+ return true;
+ } catch (err) {
+ return false;
+ }
+ })());
+ if (linkExists) {
+ return fs.unlinkSync(symlink);
+ }
+ };
switch (process.env.npm_lifecycle_event) {
case 'preinstall':
case 'update':
@@ -21,21 +35,10 @@
return content += data;
});
return res.on('end', function() {
- var linkExists;
if (!path.existsSync(folder)) {
fs.mkdirSync(folder, 0744);
}
- linkExists = ((function() {
- try {
- fs.readlinkSync(symlink);
- return true;
- } catch (err) {
- return false;
- }
- })());
- if (linkExists) {
- fs.unlinkSync(symlink);
- }
+ removeLink();
fs.writeFileSync(filepath, content);
fs.chmodSync(filepath, 0711);
return fs.symlinkSync(filepath, symlink);
@@ -45,6 +48,6 @@
});
break;
case 'preuninstall':
- fs.unlinkSync(symlink);
+ removeLink();
}
}).call(this);

0 comments on commit d05b14c

Please sign in to comment.
Something went wrong with that request. Please try again.