Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Check if entries exist before pasting them - #371

Merged
kevinsawicki merged 2 commits into
masterfrom
iz-check-if-entry-exists-before-pasting
Feb 17, 2015
Merged

kevinsawicki merged 2 commits into
masterfrom
iz-check-if-entry-exists-before-pasting

Conversation

@izuzak

@izuzak izuzak commented Feb 15, 2015

Copy link
Copy Markdown
Contributor

Fixes #356 and a bunch of other issues merged into that one:

  • 93054a6 adds a failing test case for which the test output throws the exception mentioned in the issue:

    $ apm test
    
    TreeView
    file modification
      tree-view:paste
        when pasting entries which don't exist anymore
          it skips the entry which doesn't exist
            Error: ENOENT, no such file or directory '/private/var/folders/60/ft83xwb56ssf35_50_zr1kcm0000gn/T/tree-view115115-4915-scz0ax/test-dir2/test-file-doesnt-exist1.txt'
              Error: ENOENT, no such file or directory '/private/var/folders/60/ft83xwb56ssf35_50_zr1kcm0000gn/T/tree-view115115-4915-scz0ax/test-dir2/test-file-doesnt-exist1.txt'
              at Error (native)
              at Object.fs.openSync (fs.js:503:18)
              at Object.module.(anonymous function) [as openSync] (/Applications/Atom.app/Contents/Resources/atom/common/lib/asar.js:422:20)
              at Object.fs.readFileSync (fs.js:355:15)
              at Object.fs.readFileSync (/Applications/Atom.app/Contents/Resources/atom/common/lib/asar.js:329:27)
              at TreeView.module.exports.TreeView.pasteEntries (/Users/izuzak/github/tree-view/lib/tree-view.coffee:566:42)
              at space-pen-div.atom.commands.add.tree-view:paste (/Users/izuzak/github/tree-view/lib/tree-view.coffee:115:29)
              at CommandRegistry.module.exports.CommandRegistry.handleCommandEvent (/Users/izuzak/github/atom/src/command-registry.coffee:225:27)
              at CommandRegistry.handleCommandEvent (/Users/izuzak/github/atom/src/command-registry.coffee:1:1)
              at CommandRegistry.module.exports.CommandRegistry.dispatch (/Users/izuzak/github/atom/src/command-registry.coffee:173:6)
              at [object Object].<anonymous> (/Users/izuzak/github/tree-view/spec/tree-view-spec.coffee:1179:25)
              at _fulfilled (/Users/izuzak/github/atom/node_modules/q/q.js:794:54)
              at self.promiseDispatch.done (/Users/izuzak/github/atom/node_modules/q/q.js:823:30)
              at Promise.promise.promiseDispatch (/Users/izuzak/github/atom/node_modules/q/q.js:756:13)
              at /Users/izuzak/github/atom/node_modules/q/q.js:564:44
              at flush (/Users/izuzak/github/atom/node_modules/q/q.js:110:17)
              at process._tickCallback (node.js:364:11)
    
    Finished in 29.807 seconds
    194 tests, 700 assertions, 1 failure, 0 skipped
    
  • 8a67618 adds a check so that entries which don't exist anymore are skipped when pasting. Running the test now completes without failures.

Notes:

  • using fs.existsSync is not recommended in the official docs. An alternative would be to let the code execute and catch+handle the exception. Still, I think the current solution is good enough in this case for now (and we use fs.existsSync in a bunch of other places).
  • wasn't sure how many tests would be cool for this, so added just one. The code path is the same for both files/directories (as a source and as a target) and for both copy/cut operations. Still, happy to add more tests for those variations if there's a chance this would prevent future breakage. 👍

cc @kevinsawicki for 👀

@thomasjo

Copy link
Copy Markdown
Contributor

Looks good to me at least 👍

kevinsawicki added a commit that referenced this pull request Feb 17, 2015
…ting

Check if entries exist before pasting them
@kevinsawicki
kevinsawicki merged commit a3457b5 into master Feb 17, 2015
@kevinsawicki

Copy link
Copy Markdown
Contributor

Looks good, thanks for fixing this

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Uncaught Error: ENOENT, no such file or directory 'C:\Users\Tierney\code\school\sp15_com460\projectone\week3\index.html'

3 participants