Skip to content

Commit

Permalink
Resolves opal#1725, Implement File#symlink? for Node.js
Browse files Browse the repository at this point in the history
  • Loading branch information
ggrossetie committed Dec 27, 2017
1 parent ccf1f12 commit 03ada5a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Whitespace conventions:
- Added ability to pass the port to the "server" CLI runner using the `OPAL_CLI_RUNNERS_SERVER_PORT` (explicit option passed via CLI is still working but depreted)
- Added `Array#pack` (supports only `C, S, L, Q, c, s, l, q, A, a` formats). (#1723)
- Added `String#unpack` (supports only `C, S, L, Q, S>, L>, Q>, c, s, l, q, n, N, v, V, U, w, A, a, Z, B, b, H, h, u, M, m` formats). (#1723)
- Added `File#symlink?` for Node.js. (#1725)



Expand Down
4 changes: 4 additions & 0 deletions stdlib/nodejs/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ def self.mtime path
`return executeIOAction(function(){return __fs__.statSync(#{path}).mtime})`
end

def self.symlink? path
`return executeIOAction(function(){return __fs__.lstatSync(#{path}).isSymbolicLink()})`
end

# Instance Methods

def initialize(path, flags = 'r')
Expand Down
7 changes: 7 additions & 0 deletions test/nodejs/test_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,13 @@ def test_file_check_with_symlinks
assert(File.file?('test/nodejs/fixtures/symlink-to-file'), 'test/nodejs/fixtures/symlink-to-file should be a file')
end unless windows_platform?

def test_file_symlink?
assert(File.symlink?('test/nodejs/fixtures/symlink-to-file'))
assert(File.symlink?('test/nodejs/fixtures/symlink-to-directory'))
refute(File.symlink?('test/nodejs/fixtures'))
refute(File.symlink?('test/nodejs/fixtures/hello.rb'))
end unless windows_platform?

def test_file_readable
assert !File.readable?('tmp/nonexistent')
File.write('tmp/fuz', "hello")
Expand Down

0 comments on commit 03ada5a

Please sign in to comment.