| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent b36b4f3 commit f78c8e7
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,20 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + const common = require('../common'); | ||
| 3 | + const assert = require('assert'); | ||
| 4 | + const path = require('path'); | ||
| 5 | + const fs = require('fs'); | ||
| 6 | + | ||
| 7 | + common.refreshTmpDir(); | ||
| 8 | + | ||
| 9 | + // test creating and reading hard link | ||
| 10 | + const srcPath = path.join(common.fixturesDir, 'cycles', 'root.js'); | ||
| 11 | + const dstPath = path.join(common.tmpDir, 'link1.js'); | ||
| 12 | + | ||
| 13 | + const callback = function(err) { | ||
| 14 | + if (err) throw err; | ||
| 15 | + const srcContent = fs.readFileSync(srcPath, 'utf8'); | ||
| 16 | + const dstContent = fs.readFileSync(dstPath, 'utf8'); | ||
| 17 | + assert.strictEqual(srcContent, dstContent); | ||
| 18 | + }; | ||
| 19 | + | ||
| 20 | + fs.link(srcPath, dstPath, common.mustCall(callback)); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,77 +1,50 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | - var common = require('../common'); | ||
| 3 | - var assert = require('assert'); | ||
| 4 | - var path = require('path'); | ||
| 5 | - var fs = require('fs'); | ||
| 6 | - var exec = require('child_process').exec; | ||
| 7 | - var completed = 0; | ||
| 8 | - var expected_async = 4; | ||
| 2 | + const common = require('../common'); | ||
| 3 | + const assert = require('assert'); | ||
| 4 | + const path = require('path'); | ||
| 5 | + const fs = require('fs'); | ||
| 6 | + const exec = require('child_process').exec; | ||
| 7 | + | ||
| 9 | 8 | var linkTime; | |
| 10 | 9 | var fileTime; | |
| 11 | 10 | ||
| 12 | - common.refreshTmpDir(); | ||
| 13 | - | ||
| 14 | - var runtest = function(skip_symlinks) { | ||
| 15 | - if (!skip_symlinks) { | ||
| 16 | - // test creating and reading symbolic link | ||
| 17 | - var linkData = path.join(common.fixturesDir, '/cycles/root.js'); | ||
| 18 | - var linkPath = path.join(common.tmpDir, 'symlink1.js'); | ||
| 19 | - | ||
| 20 | - fs.symlink(linkData, linkPath, function(err) { | ||
| 21 | - if (err) throw err; | ||
| 22 | - console.log('symlink done'); | ||
| 23 | - | ||
| 24 | - fs.lstat(linkPath, function(err, stats) { | ||
| 25 | - if (err) throw err; | ||
| 26 | - linkTime = stats.mtime.getTime(); | ||
| 27 | - completed++; | ||
| 28 | - }); | ||
| 29 | - | ||
| 30 | - fs.stat(linkPath, function(err, stats) { | ||
| 31 | - if (err) throw err; | ||
| 32 | - fileTime = stats.mtime.getTime(); | ||
| 33 | - completed++; | ||
| 34 | - }); | ||
| 35 | - | ||
| 36 | - fs.readlink(linkPath, function(err, destination) { | ||
| 37 | - if (err) throw err; | ||
| 38 | - assert.equal(destination, linkData); | ||
| 39 | - completed++; | ||
| 40 | - }); | ||
| 41 | - }); | ||
| 42 | - } | ||
| 43 | - | ||
| 44 | - // test creating and reading hard link | ||
| 45 | - var srcPath = path.join(common.fixturesDir, 'cycles', 'root.js'); | ||
| 46 | - var dstPath = path.join(common.tmpDir, 'link1.js'); | ||
| 47 | - | ||
| 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 | - }); | ||
| 56 | - }; | ||
| 57 | - | ||
| 58 | 11 | if (common.isWindows) { | |
| 59 | 12 | // On Windows, creating symlinks requires admin privileges. | |
| 60 | 13 | // We'll only try to run symlink test if we have enough privileges. | |
| 61 | 14 | exec('whoami /priv', function(err, o) { | |
| 62 | 15 | if (err || o.indexOf('SeCreateSymbolicLinkPrivilege') == -1) { | |
| 63 | - expected_async = 1; | ||
| 64 | - runtest(true); | ||
| 65 | - } else { | ||
| 66 | - runtest(false); | ||
| 16 | + console.log('1..0 # Skipped: insufficient privileges'); | ||
| 17 | + return; | ||
| 67 | 18 | } | |
| 68 | 19 | }); | |
| 69 | - } else { | ||
| 70 | - runtest(false); | ||
| 71 | 20 | } | |
| 72 | 21 | ||
| 73 | - process.on('exit', function() { | ||
| 74 | - assert.equal(completed, expected_async); | ||
| 75 | - assert(linkTime !== fileTime); | ||
| 22 | + common.refreshTmpDir(); | ||
| 23 | + | ||
| 24 | + // test creating and reading symbolic link | ||
| 25 | + const linkData = path.join(common.fixturesDir, '/cycles/root.js'); | ||
| 26 | + const linkPath = path.join(common.tmpDir, 'symlink1.js'); | ||
| 27 | + | ||
| 28 | + fs.symlink(linkData, linkPath, function(err) { | ||
| 29 | + if (err) throw err; | ||
| 30 | + | ||
| 31 | + fs.lstat(linkPath, common.mustCall(function(err, stats) { | ||
| 32 | + if (err) throw err; | ||
| 33 | + linkTime = stats.mtime.getTime(); | ||
| 34 | + })); | ||
| 35 | + | ||
| 36 | + fs.stat(linkPath, common.mustCall(function(err, stats) { | ||
| 37 | + if (err) throw err; | ||
| 38 | + fileTime = stats.mtime.getTime(); | ||
| 39 | + })); | ||
| 40 | + | ||
| 41 | + fs.readlink(linkPath, common.mustCall(function(err, destination) { | ||
| 42 | + if (err) throw err; | ||
| 43 | + assert.equal(destination, linkData); | ||
| 44 | + })); | ||
| 76 | 45 | }); | |
| 77 | 46 | ||
| 47 | + | ||
| 48 | + process.on('exit', function() { | ||
| 49 | + assert.notStrictEqual(linkTime, fileTime); | ||
| 50 | + }); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments