-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommit.java
More file actions
53 lines (38 loc) · 1.48 KB
/
Copy pathCommit.java
File metadata and controls
53 lines (38 loc) · 1.48 KB
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
public class Commit extends ListFiles implements Modifying {
public Commit(VCS vcs) {
super(vcs);
}
public String getInformation() {
return "Files: Copy and Move \n" +
"Directory: create";
}
@Override
public void execute() {
String timeStampDir = this.createTimeStampDir();
this.moveOldBackupDirFiles(timeStampDir);
this.copyRootFiles();
System.out.println("Committed the following files:");
super.execute();
}
private String createTimeStampDir() {
String timeStampDir = Util.appendFileOrDirname(vcs.getBackupDir(), Util.getTimestamp());
Util.mkdir(timeStampDir);
return timeStampDir;
}
private void moveOldBackupDirFiles(String timeStampDir) {
String[] backupFiles = Util.listFiles(vcs.getBackupDir());
for(String file : backupFiles) {
String srcFilename = Util.appendFileOrDirname(vcs.getBackupDir(), file);
String destFilename = Util.appendFileOrDirname(timeStampDir, file);
Util.moveFile(srcFilename, destFilename);
}
}
private void copyRootFiles() {
String[] rootFiles = Util.listFiles(vcs.getRootDir());
for(String file : rootFiles) {
String srcFilename = Util.appendFileOrDirname(vcs.getRootDir(), file);
String destFilename = Util.appendFileOrDirname(vcs.getBackupDir(), file);
Util.copyFile(srcFilename, destFilename);
}
}
}