import java util import java nio file Files import java io жуткий говн

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
import java.util.*;
import java.nio.file.Files;
import java.io.*;
//жуткий говнокод,все писалось на дебагах,поберегите свои глаза.
public class Sync {
private static void CheckDelete(File s, File d,ArrayList<String> Copy,ArrayList<String> Delete,String ParentPath) throws IOException
{
String[] Sl=s.list(), Dl=d.list();
int len2=Sl.length,len1=Dl.length,i,j;
String ParentPathForRec;
//удаление
for(i=0;i<len1;i++) {
File f1 = new File(d + "/" + Dl[i]);
//если f1-файл
if (f1.isFile() && !Dl[i].equals(".DS_Store")) {
for (j = 0; j < len2; j++) {
File f2 = new File(s + "/" + Sl[j]);
if (f2.isFile() && Sl[j].equals(Dl[i])) {
if (Arrays.equals(Files.readAllBytes(f1.toPath()), Files.readAllBytes(f2.toPath())))
break;
}
if (j + 1 == len2) {
Delete.add(ParentPath + Dl[i]);
}
}
}
//если f1-каталог
else if (!Dl[i].equals(".DS_Store")) {
for (j = 0; j < len2; j++) {
File f2 = new File(s + "/" + Sl[j]);
if (Dl[i].equals(Sl[j])) {
ParentPathForRec = ParentPath + Sl[j] + "/";
CheckDelete(f2, f1, Copy, Delete, ParentPathForRec);
break;
}
if (j + 1 == len2) {
Delete.add(ParentPath + Dl[i]);
}
}
}
}
}
private static void CheckCopy(File s, File d,ArrayList<String> Copy,ArrayList<String> Delete,String ParentPath) throws IOException
{
String[] Sl=s.list(), Dl=d.list();
int len2=Sl.length,len1=Dl.length,i,j;
String ParentPathForRec;
//копирование
for(i=0;i<len2;i++)
{
File f3 = new File(s + "/" + Sl[i]);
//если f3-файл
if(f3.isFile() && !Sl[i].equals(".DS_Store")) {
for (j = 0; j < len1; j++) {
File f4 = new File(d + "/" + Dl[j]);
if (f4.isFile() && Sl[i].equals(Dl[j])) {
if (Arrays.equals(Files.readAllBytes(f3.toPath()), Files.readAllBytes(f4.toPath())))
break;
}
if (j + 1 == len1 && f3.isFile()) {
Copy.add(ParentPath + Sl[i]);
}
}
}
//если f3-каталог
else if (!Sl[i].equals(".DS_Store")) {
for (j = 0; j < len1; j++) {
File f4 = new File(d + "/" + Dl[j]);
if (Dl[j].equals(Sl[i])) {
ParentPathForRec = ParentPath + Sl[i] + "/";
CheckCopy(f3, f4, Copy, Delete, ParentPathForRec);
break;
}
if(j + 1 == len1 && !f3.isFile())
{
String[] Directory_404=f3.list();
int Len_404=Directory_404.length;
for(int k=0;k<Len_404;k++)
{
if(!Directory_404[k].equals(".DS_Store"))
Copy.add(ParentPath + Sl[i] + "/" + Directory_404[k]);
}
}
}
}
}
}
public static void main(String[] args) throws IOException{
File S=new File(args[0]), D=new File (args[1]);
ArrayList<String> Copy=new ArrayList<String>(),Delete=new ArrayList<String>();
String ParentPath="";
CheckDelete(S, D, Copy, Delete, ParentPath);
CheckCopy(S, D, Copy, Delete, ParentPath);
Collections.sort(Delete);
Collections.sort(Copy);
int i=0;
if(Delete.size()==0 && Copy.size()==0)
System.out.println("IDENTICAL");
for(i = 0; i < Delete.size(); i++){
System.out.println("DELETE" + " " + Delete.get(i));
}
for(i = 0; i < Copy.size(); i++){
System.out.println("COPY" + " " + Copy.get(i));
}
}
}