@@ -25,44 +25,58 @@ getLogger = ->
2525class RemoteSync
2626 constructor : (@projectPath , @configPath ) ->
2727 Host ?= require ' ./model/host'
28-
28+
2929 @host = new Host (@configPath )
3030 @ initIgnore (@host )
31-
31+
3232 initIgnore : (host )->
3333 ignore = host .ignore ? .split (" ," )
3434 host .isIgnore = (filePath , relativizePath ) =>
3535 return false unless ignore
36-
36+
3737 relativizePath = @projectPath unless relativizePath
3838 filePath = path .relative relativizePath, filePath
3939
4040 minimatch ?= require " minimatch"
4141 for pattern in ignore
4242 return true if minimatch filePath, pattern, { matchBase : true , dot : true }
4343 return false
44-
44+
4545 isIgnore : (filePath , relativizePath )->
4646 return @host .isIgnore (filePath, relativizePath)
47-
47+
4848 dispose : ->
4949 if @transport
5050 @transport .dispose ()
5151 @transport = null
5252
53+ deleteFile : (filePath ) ->
54+ return if @ isIgnore (filePath)
55+
56+ if not uploadCmd
57+ UploadListener = require " ./UploadListener"
58+ uploadCmd = new UploadListener getLogger ()
59+
60+ uploadCmd .handleDelete (filePath, @ getTransport ())
61+ for t in @ getUploadMirrors ()
62+ uploadCmd .handleDelete (filePath, t)
63+
64+ if @host .deleteLocal
65+ fs .removeSync (filePath)
66+
5367 downloadFolder : (localPath , targetPath , callback )->
5468 DownloadCmd ?= require ' ./commands/DownloadAllCommand'
5569 DownloadCmd .run (getLogger (), @ getTransport (),
5670 localPath, targetPath, callback)
57-
71+
5872 downloadFile : (localPath )->
5973 realPath = path .relative (@projectPath , localPath)
6074 realPath = path .join (@host .target , realPath).replace (/ \\ / g , " /" )
6175 @ getTransport ().download (realPath)
62-
76+
6377 uploadFile : (filePath ) ->
6478 return if @ isIgnore (filePath)
65-
79+
6680 if not uploadCmd
6781 UploadListener = require " ./UploadListener"
6882 uploadCmd = new UploadListener getLogger ()
@@ -74,7 +88,7 @@ class RemoteSync
7488 uploadFolder : (dirPath )->
7589 fs .traverseTree dirPath, @uploadFile .bind (@ ), =>
7690 return not @ isIgnore (dirPath)
77-
91+
7892 uploadGitChange : (dirPath )->
7993 repos = atom .project .getRepositories ()
8094 curRepo = null
@@ -85,15 +99,15 @@ class RemoteSync
8599 curRepo = repo
86100 break
87101 return unless curRepo
88-
102+
89103 isChangedPath = (path )->
90104 status = curRepo .getCachedPathStatus (path)
91105 return curRepo .isStatusModified (status) or curRepo .isStatusNew (status)
92-
106+
93107 fs .traverseTree dirPath, (path )=>
94108 @ uploadFile (path) if isChangedPath (path)
95109 , (path )=> return not @ isIgnore (path)
96-
110+
97111 createTransport : (host )->
98112 if host .transport is ' scp' or host .transport is ' sftp'
99113 ScpTransport ?= require " ./transports/ScpTransport"
@@ -129,13 +143,13 @@ class RemoteSync
129143
130144 @ getTransport ().download realPath, targetPath, =>
131145 @ diff localPath, targetPath
132-
146+
133147 diffFolder : (localPath )->
134148 os = require " os" if not os
135149 targetPath = path .join os .tmpDir (), " remote-sync"
136150 @ downloadFolder localPath, targetPath, =>
137151 @ diff localPath, targetPath
138-
152+
139153 diff : (localPath , targetPath ) ->
140154 targetPath = path .join (targetPath, path .relative (@projectPath , localPath))
141155 diffCmd = atom .config .get (' remote-sync.difftoolCommand' )
@@ -146,22 +160,22 @@ class RemoteSync
146160 Command error: #{ err}
147161 command: #{ diffCmd} #{ localPath} #{ targetPath}
148162 """
149-
150- module .exports =
163+
164+ module .exports =
151165 create : (projectPath )->
152166 configPath = path .join projectPath, atom .config .get (' remote-sync.configFileName' )
153167 return unless fs .existsSync configPath
154168 return new RemoteSync (projectPath, configPath)
155-
169+
156170 configure : (projectPath , callback )->
157171 HostView ?= require ' ./view/host-view'
158172 Host ?= require ' ./model/host'
159173 EventEmitter ?= require (" events" ).EventEmitter
160-
174+
161175 emitter = new EventEmitter ()
162176 emitter .on " configured" , callback
163177
164178 configPath = path .join projectPath, atom .config .get (' remote-sync.configFileName' )
165179 host = new Host (configPath, emitter)
166180 view = new HostView (host)
167- view .attach ()
181+ view .attach ()
0 commit comments