|
19 | 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
20 | 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21 | 21 |
|
22 |
| -// libuv-broken |
23 |
| - |
24 |
| - |
25 | 22 | var common = require('../common');
|
26 | 23 | var assert = require('assert');
|
27 | 24 | var path = require('path');
|
28 | 25 | var fs = require('fs');
|
| 26 | +var exec = require('child_process').exec; |
29 | 27 | var completed = 0;
|
| 28 | +var expected_tests = 2; |
| 29 | + |
| 30 | +var is_windows = process.platform === 'win32'; |
| 31 | + |
| 32 | +var runtest = function(skip_symlinks) { |
| 33 | + if (!skip_symlinks) { |
| 34 | + // test creating and reading symbolic link |
| 35 | + var linkData = path.join(common.fixturesDir, '/cycles/root.js'); |
| 36 | + var linkPath = path.join(common.tmpDir, 'symlink1.js'); |
| 37 | + |
| 38 | + // Delete previously created link |
| 39 | + try { |
| 40 | + fs.unlinkSync(linkPath); |
| 41 | + } catch(e) |
| 42 | + {} |
| 43 | + |
| 44 | + fs.symlink(linkData, linkPath, function(err) { |
| 45 | + if (err) throw err; |
| 46 | + console.log('symlink done'); |
| 47 | + // todo: fs.lstat? |
| 48 | + fs.readlink(linkPath, function(err, destination) { |
| 49 | + if (err) throw err; |
| 50 | + assert.equal(destination, linkData); |
| 51 | + completed++; |
| 52 | + }); |
| 53 | + }); |
| 54 | + } |
30 | 55 |
|
31 |
| -// test creating and reading symbolic link |
32 |
| -var linkData = path.join(common.fixturesDir, '/cycles/root.js'); |
33 |
| -var linkPath = path.join(common.tmpDir, 'symlink1.js'); |
34 |
| -fs.symlink(linkData, linkPath, function(err) { |
35 |
| - if (err) throw err; |
36 |
| - console.log('symlink done'); |
37 |
| - // todo: fs.lstat? |
38 |
| - fs.readlink(linkPath, function(err, destination) { |
| 56 | + // test creating and reading hard link |
| 57 | + var srcPath = path.join(common.fixturesDir, 'cycles', 'root.js'); |
| 58 | + var dstPath = path.join(common.tmpDir, 'link1.js'); |
| 59 | + |
| 60 | + // Delete previously created link |
| 61 | + try { |
| 62 | + fs.unlinkSync(dstPath); |
| 63 | + } catch(e) |
| 64 | + {} |
| 65 | + |
| 66 | + fs.link(srcPath, dstPath, function(err) { |
39 | 67 | if (err) throw err;
|
40 |
| - assert.equal(destination, linkData); |
| 68 | + console.log('hard link done'); |
| 69 | + var srcContent = fs.readFileSync(srcPath, 'utf8'); |
| 70 | + var dstContent = fs.readFileSync(dstPath, 'utf8'); |
| 71 | + assert.equal(srcContent, dstContent); |
41 | 72 | completed++;
|
42 | 73 | });
|
43 |
| -}); |
| 74 | +} |
44 | 75 |
|
45 |
| -// test creating and reading hard link |
46 |
| -var srcPath = path.join(common.fixturesDir, 'cycles', 'root.js'); |
47 |
| -var dstPath = path.join(common.tmpDir, 'link1.js'); |
48 |
| -fs.link(srcPath, dstPath, function(err) { |
49 |
| - if (err) throw err; |
50 |
| - console.log('hard link done'); |
51 |
| - var srcContent = fs.readFileSync(srcPath, 'utf8'); |
52 |
| - var dstContent = fs.readFileSync(dstPath, 'utf8'); |
53 |
| - assert.equal(srcContent, dstContent); |
54 |
| - completed++; |
55 |
| -}); |
| 76 | +if (is_windows) { |
| 77 | + // On Windows, creating symlinks requires admin privileges. |
| 78 | + // We'll only try to run symlink test if we have enough privileges. |
| 79 | + exec("whoami /priv", function(err, o) { |
| 80 | + if (err || o.indexOf('SeCreateSymbolicLinkPrivilege') == -1) { |
| 81 | + expected_tests = 1; |
| 82 | + runtest(true); |
| 83 | + } else { |
| 84 | + runtest(false); |
| 85 | + } |
| 86 | + }); |
| 87 | +} else { |
| 88 | + runtest(false); |
| 89 | +} |
56 | 90 |
|
57 | 91 | process.on('exit', function() {
|
58 |
| - assert.equal(completed, 2); |
| 92 | + assert.equal(completed, expected_tests); |
59 | 93 | });
|
60 | 94 |
|
0 commit comments