-
Notifications
You must be signed in to change notification settings - Fork 35
Move file-moving logic from tree-view's MoveDialog to fsPlus.moveSync #18
Conversation
Regarding the possibility of breaking existing packages that rely on I see |
I accidentally closed this pull request by hitting a keyboard shortcut, would still very much appreciate comments or a merge. :) |
@@ -4,6 +4,7 @@ path = require 'path' | |||
|
|||
_ = require 'underscore-plus' | |||
async = require 'async' | |||
{Promise} = require 'es6-promise' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For things like this that might be built-in depending on the context, we try to use the global when available and fall back to the require when it isn't there.
So something like:
Promise = global.Promise ? require('es6-promise').Promise
@@ -523,4 +542,18 @@ lstatSyncNoException ?= (args...) -> | |||
isPathValid = (pathToCheck) -> | |||
pathToCheck? and typeof pathToCheck is 'string' and pathToCheck.length > 0 | |||
|
|||
isMoveTargetValidSync = (source, target) -> | |||
try | |||
oldStat = fs.statSync(source) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line and the line below it should use statSyncNoException
for speed 🐎
Basically it removes the need for a try
/catch
and instead you can just return true
if either oldStat
or newStat
is false
.
Move file-moving logic from tree-view's MoveDialog to fsPlus.moveSync
Thanks for this! 🚢 |
As far as I can tell, the tree-view's
MoveDialog
is the only client offsPlus.moveSync
-- https://github.com/atom/tree-view/blob/48fd001687f14bb8538fe6c92f59d9774fa87c4f/lib/move-dialog.coffee#L31. It adds a lot of custom logic (e.g. checking when a move is valid, creating the target's parent directory if it doesn't exist, etc) that could be useful for other callers.I'm specifically making this move so we can reuse the function for remote file support.