parent
462bd11a75
commit
21ab7839e3
@ -1,13 +0,0 @@
|
||||
package com.olexyn.ensync;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Core {
|
||||
|
||||
|
||||
public Core(){
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,76 @@
|
||||
package com.olexyn.ensync;
|
||||
|
||||
import com.olexyn.ensync.artifacts.SyncDirectory;
|
||||
import com.olexyn.ensync.artifacts.SyncEntity;
|
||||
import com.olexyn.ensync.artifacts.SyncFile;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class Flow {
|
||||
|
||||
|
||||
public Flow(){
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public void start() {
|
||||
File asdf = new File("/home/user/");
|
||||
System.out.println(asdf.lastModified());
|
||||
|
||||
Tools tools = new Tools();
|
||||
Execute x = new Execute();
|
||||
|
||||
|
||||
SyncEntity syncEntity = new SyncEntity("test");
|
||||
syncEntity.addDirectory("/home/user/test/a");
|
||||
syncEntity.addDirectory("/home/user/test/b");
|
||||
//syncEntity.addDirectory("/home/user/test/c");
|
||||
|
||||
|
||||
for (Map.Entry<String, SyncDirectory> entry : syncEntity.syncDirectories.entrySet()) {
|
||||
SyncDirectory syncDirectory = entry.getValue();
|
||||
String path = syncDirectory.path;
|
||||
String stateFilePath = syncDirectory.stateFilePath(path);
|
||||
|
||||
if (new File(stateFilePath).exists()) {
|
||||
syncDirectory.readStateFile(syncDirectory.path);
|
||||
} else {
|
||||
syncDirectory.writeStateFile(path);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
while (true) {
|
||||
|
||||
for (Map.Entry<String, SyncDirectory> entry : syncEntity.syncDirectories.entrySet()) {
|
||||
|
||||
SyncDirectory syncDirectory = entry.getValue();
|
||||
|
||||
String path = syncDirectory.path;
|
||||
|
||||
syncDirectory.readState(path);
|
||||
|
||||
List<SyncFile> listCreated = syncDirectory.makeListCreated(path);
|
||||
List<SyncFile> listDeleted = syncDirectory.makeListDeleted(path);
|
||||
List<SyncFile> listModified = syncDirectory.makeListModified(path);
|
||||
|
||||
syncDirectory.doCreate(listCreated);
|
||||
syncDirectory.doDelete(listDeleted);
|
||||
syncDirectory.doModify(listModified);
|
||||
|
||||
syncDirectory.writeStateFile(path);
|
||||
|
||||
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
|
||||
}
|
||||
}}
|
||||
}
|
||||
}
|
@ -1,71 +1,16 @@
|
||||
package com.olexyn.ensync;
|
||||
|
||||
import com.olexyn.ensync.artifacts.SyncDirectory;
|
||||
import com.olexyn.ensync.artifacts.SyncEntity;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class Main {
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
|
||||
Tools tools = new Tools();
|
||||
Execute x = new Execute();
|
||||
|
||||
|
||||
SyncEntity syncEntity = new SyncEntity("test");
|
||||
syncEntity.addDirectory("/home/user/test/a");
|
||||
syncEntity.addDirectory("/home/user/test/b");
|
||||
//syncEntity.addDirectory("/home/user/test/c");
|
||||
|
||||
int br1 = 0;
|
||||
|
||||
while (true) {
|
||||
|
||||
for (Map.Entry<String, SyncDirectory> entry : syncEntity.syncDirectories.entrySet()) {
|
||||
|
||||
SyncDirectory syncDirectory = entry.getValue();
|
||||
|
||||
|
||||
syncDirectory.updateStateFileNew();
|
||||
syncDirectory.updatePoolNew();
|
||||
|
||||
syncDirectory.getListCreated();
|
||||
syncDirectory.getListDeleted();
|
||||
|
||||
|
||||
//
|
||||
|
||||
syncDirectory.doSyncOps();
|
||||
|
||||
|
||||
//
|
||||
// WARNING:
|
||||
// Be very carefull when to update the StateFileOld
|
||||
// i.e. you create a File and update StateFileOld without updating
|
||||
// -> create newFile -> update StateFileNew-> getListCreated contains newFile -> addToMapCreated -> create copies as needed -> updateStateFileOld -> OK
|
||||
// -> create newFile -> update StateFileOld -> getListDeletd contains newFile -> VERY BAD
|
||||
//
|
||||
syncDirectory.updateStateFileNew();
|
||||
syncDirectory.updatePoolNew();
|
||||
|
||||
syncDirectory.updateStateFileOld();
|
||||
syncDirectory.updatePoolOld();
|
||||
|
||||
new Flow().start();
|
||||
|
||||
|
||||
|
||||
}
|
||||
//Map<String,File> mapCreated = syncEntity.getMapCreated();
|
||||
//Map<String,File> mapDeleted = syncEntity.getMapDeleted();
|
||||
|
||||
int br = 0;
|
||||
try {Thread.sleep(1000);}
|
||||
catch (InterruptedException e){
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,36 @@
|
||||
package com.olexyn.ensync.artifacts;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class Data {
|
||||
|
||||
|
||||
Map<String, Map<String, SyncFile>> database;
|
||||
|
||||
|
||||
|
||||
|
||||
public Data(){
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
package com.olexyn.ensync.artifacts;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class StateFile {
|
||||
|
||||
private final String[] types = new String[]{ "OLD" , "NEW"};
|
||||
|
||||
public String stateFilePath;
|
||||
public File stateFileOld;
|
||||
private Map<String, File> poolOld = new HashMap<>();
|
||||
|
||||
|
||||
public StateFile(){
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public void update(){
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package com.olexyn.ensync.artifacts;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class SyncFile extends File {
|
||||
|
||||
|
||||
// Very IMPORTANT field. Allows to store lastModified as it is stored in the StateFile.
|
||||
private long lastModifiedOld = 0;
|
||||
|
||||
|
||||
public SyncFile(String pathname) {
|
||||
super(pathname);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public long lastModifiedOld(){
|
||||
return lastModifiedOld;
|
||||
}
|
||||
|
||||
public void setLastModifiedOld(long value){
|
||||
lastModifiedOld = value;
|
||||
}
|
||||
|
||||
}
|
Before Width: | Height: | Size: 54 KiB After Width: | Height: | Size: 44 KiB |
Loading…
Reference in new issue