Commits

Ivan Inozemtsev committed 6ee0293

working exampke

Comments (0)

Files changed (1)

 class SyncDirs
 {
+  static File child(File parent, Str name) { File(parent.uri + name.toUri, false) }
+  
   static Void sync(File from, File to)
   {
     Str[] fromFileNames := from.list.map { it.name }
     
     //delete what is not present in 'from'
     toFileNames
-      .findAll |t| { !fromFileNames.any |f| { f.equalsIgnoreCase(t) } }
-      .each { (to + it.toUri).delete }
+      .findAll |t| { fromFileNames.all |f| { !f.equalsIgnoreCase(t) } }
+      .each { child(to, it).delete }
     
     //copy what is not present in 'to'
     fromFileNames
-      .findAll |f| { !toFileNames.any |t| { t.equalsIgnoreCase(f) } }
-      .each { (from + it.toUri).copyTo(to + it.toUri) }
+      .findAll |f| { toFileNames.all |t| { !t.equalsIgnoreCase(f) } }
+      .each { (File(from.uri + it.toUri, false)).copyInto(to) }
     
     //find intersection
-    toFileNames
-      .findAll |t| { fromFileNames.any |f| { f.equalsIgnoreCase(t) } }
-      .each |c| { 
-        fromChild := from + c.toUri
-        toChild := to + c.toUri
-        
-        if(fromChild.isDir != toChild.isDir) 
-        {
-          toChild.delete
-          fromChild.copyTo(toChild)
-          return
-        } 
-        if(fromChild.isDir) sync(fromChild, toChild)
+    toFileNames.intersection(fromFileNames).each |c| { 
+      fromChild := File(from.uri + c.toUri, false)
+      toChild := File(to.uri + c.toUri, false)
+      
+      if(fromChild.isDir != toChild.isDir) 
+      {
+        toChild.delete
+        fromChild.copyInto(to)
+        return
+      } 
+      if(fromChild.isDir) sync(fromChild, toChild)
     }