Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
fix test-fs-chmod test
  • Loading branch information
Igor Zinkovsky authored and piscisaureus committed Sep 9, 2011
1 parent 03c2f62 commit 85357ab
Showing 1 changed file with 38 additions and 11 deletions.
49 changes: 38 additions & 11 deletions test/simple/test-fs-chmod.js
Expand Up @@ -19,27 +19,45 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.

// libuv-broken


var common = require('../common');
var assert = require('assert');
var path = require('path');
var fs = require('fs');
var got_error = false;
var success_count = 0;
var mode_async;
var mode_sync;
var is_windows = process.platform === 'win32';

// On Windows chmod is only able to manipulate read-only bit
if (is_windows) {
mode_async = 0400; // read-only
mode_sync = 0600; // read-write
} else {
mode_async = 0777;
mode_sync = 0644;
}

var file = path.join(common.fixturesDir, 'a.js');

fs.chmod(file, '0777', function(err) {
fs.chmod(file, mode_async.toString(), function(err) {
if (err) {
got_error = true;
} else {
console.log(fs.statSync(file).mode);
assert.equal(0777, fs.statSync(file).mode & 0777);

fs.chmodSync(file, 0644);
assert.equal(0644, fs.statSync(file).mode & 0777);
if (is_windows) {
assert.ok((fs.statSync(file).mode & 0777) & mode_async);
} else {
assert.equal(mode_async, fs.statSync(file).mode & 0777);
}

fs.chmodSync(file, mode_sync);
if (is_windows) {
assert.ok((fs.statSync(file).mode & 0777) & mode_sync);
} else {
assert.equal(mode_sync, fs.statSync(file).mode & 0777);
}
success_count++;
}
});
Expand All @@ -50,15 +68,24 @@ fs.open(file, 'a', function(err, fd) {
console.error(err.stack);
return;
}
fs.fchmod(fd, '0777', function(err) {
fs.fchmod(fd, mode_async.toString(), function(err) {
if (err) {
got_error = true;
} else {
console.log(fs.fstatSync(fd).mode);
assert.equal(0777, fs.fstatSync(fd).mode & 0777);

fs.fchmodSync(fd, 0644);
assert.equal(0644, fs.fstatSync(fd).mode & 0777);
if (is_windows) {
assert.ok((fs.fstatSync(fd).mode & 0777) & mode_async);
} else {
assert.equal(mode_async, fs.fstatSync(fd).mode & 0777);
}

fs.fchmodSync(fd, mode_sync);
if (is_windows) {
assert.ok((fs.fstatSync(fd).mode & 0777) & mode_sync);
} else {
assert.equal(mode_sync, fs.fstatSync(fd).mode & 0777);
}
success_count++;
}
});
Expand Down

0 comments on commit 85357ab

Please sign in to comment.