This commit is contained in:
Robert Vokac 2024-12-27 18:34:07 +01:00
parent 5c58cecb61
commit bcb9956c6e
Signed by: robertvokac
GPG Key ID: FB9CE8E20AADA55F
10 changed files with 19 additions and 26 deletions

View File

@ -185,7 +185,7 @@ public class CheckCommand implements Command {
LOG.error("Part {}: KO. Failed.", CheckCommandPart.MIGRATE_DB_SCHEMA_IF_NEEDED.number); LOG.error("Part {}: KO. Failed.", CheckCommandPart.MIGRATE_DB_SCHEMA_IF_NEEDED.number);
throw new RuntimeException("Part " + CheckCommandPart.MIGRATE_DB_SCHEMA_IF_NEEDED.number + ": KO. Failed."); throw new RuntimeException("Part " + CheckCommandPart.MIGRATE_DB_SCHEMA_IF_NEEDED.number + ": KO. Failed.");
} }
} catch (Exception e) { } catch (RuntimeException e) {
LOG.error("Part {}: KO. {}", CheckCommandPart.MIGRATE_DB_SCHEMA_IF_NEEDED.number, e.getMessage()); LOG.error("Part {}: KO. {}", CheckCommandPart.MIGRATE_DB_SCHEMA_IF_NEEDED.number, e.getMessage());
return false; return false;
} }
@ -212,7 +212,7 @@ public class CheckCommand implements Command {
List<File> filesAlreadyFound = new ArrayList<>(); List<File> filesAlreadyFound = new ArrayList<>();
List<File> filesInDirList = foundFilesInCurrentDir(bitBackupFiles.getWorkingDir(), filesAlreadyFound, bitBackupFiles); List<File> filesInDirList = foundFilesInCurrentDir(bitBackupFiles.getWorkingDir(), filesAlreadyFound, bitBackupFiles);
Utils.writeTextToFile(bitbackupindex.toString(), new File("bitbackupindex")); Utils.writeTextToFile(bitbackupindexSB.toString(), bitBackupFiles.getBitbackupindex());
ListSet<File> listSet = new ListSet<>(filesInDirList, f -> loadPathButOnlyTheNeededPart(bitBackupFiles.getWorkingDir(), f)); ListSet<File> listSet = new ListSet<>(filesInDirList, f -> loadPathButOnlyTheNeededPart(bitBackupFiles.getWorkingDir(), f));
LOG.info("Part {}: Found {} files.", CheckCommandPart.FOUND_FILES_IN_FILESYSTEM.number, listSet.size()); LOG.info("Part {}: Found {} files.", CheckCommandPart.FOUND_FILES_IN_FILESYSTEM.number, listSet.size());
@ -225,7 +225,7 @@ public class CheckCommand implements Command {
private String loadPathButOnlyTheNeededPart(File currentDir, File file) { private String loadPathButOnlyTheNeededPart(File currentDir, File file) {
return file.getAbsolutePath().substring(currentDir.getAbsolutePath().length() + 1); return file.getAbsolutePath().substring(currentDir.getAbsolutePath().length() + 1);
} }
private StringBuilder bitbackupindex = new StringBuilder(); private final StringBuilder bitbackupindexSB = new StringBuilder();
static int iii = 0; static int iii = 0;
private int foundFiles; private int foundFiles;
@ -238,13 +238,13 @@ public class CheckCommand implements Command {
boolean isBitBackupIgnore = f.getName().equals(bitBackupFiles.getBitBackupIgnore().getName()); boolean isBitBackupIgnore = f.getName().equals(bitBackupFiles.getBitBackupIgnore().getName());
if (isBitBackupIgnore && !f.getAbsolutePath().equals(bitBackupFiles.getBitBackupIgnore().getAbsoluteFile())) { if (isBitBackupIgnore && !f.getAbsolutePath().equals(bitBackupFiles.getBitBackupIgnore().getAbsolutePath())) {
bitBackupFiles.getBitBackupIgnoreRegex().addBitBackupIgnoreFile(f, bitBackupFiles.getWorkingDir()); bitBackupFiles.getBitBackupIgnoreRegex().addBitBackupIgnoreFile(f, bitBackupFiles.getWorkingDir());
} }
if (f.isDirectory()) { if (f.isDirectory()) {
++foundDirs; ++foundDirs;
try { try {
bitbackupindex.append(new FileEntry(f).toCsvLine()).append("\n"); bitbackupindexSB.append(new FileEntry(f).toCsvLine()).append("\n");
} catch (IOException ex) { } catch (IOException ex) {
java.util.logging.Logger.getLogger(CheckCommand.class.getName()).log(Level.SEVERE, null, ex); java.util.logging.Logger.getLogger(CheckCommand.class.getName()).log(Level.SEVERE, null, ex);
} }
@ -264,7 +264,7 @@ public class CheckCommand implements Command {
continue; continue;
} }
try { try {
bitbackupindex.append(new FileEntry(f).toCsvLine()).append("\n"); bitbackupindexSB.append(new FileEntry(f).toCsvLine()).append("\n");
} catch (IOException ex) { } catch (IOException ex) {
java.util.logging.Logger.getLogger(CheckCommand.class.getName()).log(Level.SEVERE, null, ex); java.util.logging.Logger.getLogger(CheckCommand.class.getName()).log(Level.SEVERE, null, ex);
} }

View File

@ -39,7 +39,7 @@ public class HelpCommand implements Command {
} }
@Override @Override
public String run(BitBackupArgs bitInspectorArgs) { public String run(BitBackupArgs bitBackupArgs) {
String str = """ String str = """
NAME NAME
bitbackup - " Bit Backup" bitbackup - " Bit Backup"

View File

@ -42,7 +42,7 @@ private static final Logger LOG = LogManager.getLogger(VersionCommand.class);
} }
@Override @Override
public String run(BitBackupArgs bitInspectorArgs) { public String run(BitBackupArgs bitBackupArgs) {
String result = "Bit Backup 0.0.0-SNAPSHOT"; String result = "Bit Backup 0.0.0-SNAPSHOT";
LOG.info(result); LOG.info(result);
return result; return result;

View File

@ -32,12 +32,12 @@ import com.robertvokac.bitbackup.commands.VersionCommand;
* *
* @author <a href="mailto:mail@robertvokac.com">Robert Vokac</a> * @author <a href="mailto:mail@robertvokac.com">Robert Vokac</a>
*/ */
public class BitInspector { public class BitBackup {
private static final Logger LOG = LogManager.getLogger(BitInspector.class); private static final Logger LOG = LogManager.getLogger(BitBackup.class);
private final Set<Command> commandImplementations; private final Set<Command> commandImplementations;
public BitInspector() { public BitBackup() {
commandImplementations = new HashSet<>(); commandImplementations = new HashSet<>();
commandImplementations.add(new CheckCommand()); commandImplementations.add(new CheckCommand());
commandImplementations.add(new HelpCommand()); commandImplementations.add(new HelpCommand());

View File

@ -43,7 +43,7 @@ public class BitBackupArgs {
return array; return array;
} }
public BitBackupArgs(BitInspectorCommand command, Map<String, String> map) { public BitBackupArgs(BitBackupCommand command, Map<String, String> map) {
this(convertToStringArray(command.name().toLowerCase(), map)); this(convertToStringArray(command.name().toLowerCase(), map));
} }

View File

@ -24,6 +24,6 @@ package com.robertvokac.bitbackup.core;
* *
* @author <a href="mailto:mail@robertvokac.com">Robert Vokac</a> * @author <a href="mailto:mail@robertvokac.com">Robert Vokac</a>
*/ */
public enum BitInspectorCommand { public enum BitBackupCommand {
CHECK, HELP, VERSION; CHECK, HELP, VERSION;
} }

View File

@ -36,9 +36,9 @@ public class BitBackupContext {
private final String directoryWhereSqliteFileIs; private final String directoryWhereSqliteFileIs;
private ConnectionFactory connectionFactory; private ConnectionFactory connectionFactory;
@Getter @Getter
private SystemItemRepository systemItemRepository; private final SystemItemRepository systemItemRepository;
@Getter @Getter
private FileRepository fileRepository; private final FileRepository fileRepository;
public BitBackupContext(String directoryWhereSqliteFileIs) { public BitBackupContext(String directoryWhereSqliteFileIs) {
this.directoryWhereSqliteFileIs = directoryWhereSqliteFileIs; this.directoryWhereSqliteFileIs = directoryWhereSqliteFileIs;

View File

@ -39,10 +39,8 @@ public class BitBackupFiles {
private final File bitBackupIgnore; private final File bitBackupIgnore;
private final BitBackupIgnoreRegex bitBackupIgnoreRegex; private final BitBackupIgnoreRegex bitBackupIgnoreRegex;
private final File bitBackupReportCsv; private final File bitBackupReportCsv;
private final File bitbackupindex;
public BitBackupFiles(BitBackupArgs bitInspectorArgs) { public BitBackupFiles(BitBackupArgs bitInspectorArgs) {
workingDir = new File(bitInspectorArgs.hasArgument("dir") ? bitInspectorArgs.getArgument("dir") : "."); workingDir = new File(bitInspectorArgs.hasArgument("dir") ? bitInspectorArgs.getArgument("dir") : ".");
workingDirAbsolutePath = workingDir.getAbsolutePath(); workingDirAbsolutePath = workingDir.getAbsolutePath();
@ -51,5 +49,6 @@ public class BitBackupFiles {
bitBackupIgnore = new File(workingDirAbsolutePath + "/.bitbackupignore"); bitBackupIgnore = new File(workingDirAbsolutePath + "/.bitbackupignore");
bitBackupIgnoreRegex = new BitBackupIgnoreRegex(bitBackupIgnore); bitBackupIgnoreRegex = new BitBackupIgnoreRegex(bitBackupIgnore);
bitBackupReportCsv = new File(workingDirAbsolutePath + "/.bitbackupreport.csv"); bitBackupReportCsv = new File(workingDirAbsolutePath + "/.bitbackupreport.csv");
bitbackupindex = new File(workingDirAbsolutePath + "/.bitbackupindex.csv");
} }
} }

View File

@ -28,8 +28,8 @@ public class Main {
public static void main(String[] args) { public static void main(String[] args) {
System.out.println("Bir - Detects bit rotten files in the given directory to keep your files forever.\n"); System.out.println("Bir - Detects bit rotten files in the given directory to keep your files forever.\n");
BitInspector bitInspector = new BitInspector(); BitBackup bitBackup = new BitBackup();
bitInspector.run(args); bitBackup.run(args);
} }

View File

@ -19,12 +19,6 @@
/////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////
package com.robertvokac.bitbackup.persistence.impl.sqlite; package com.robertvokac.bitbackup.persistence.impl.sqlite;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.robertvokac.bitbackup.core.Constants;
import com.robertvokac.bitbackup.core.Utils; import com.robertvokac.bitbackup.core.Utils;
import com.robertvokac.dbmigration.core.main.DBMigration; import com.robertvokac.dbmigration.core.main.DBMigration;
import com.robertvokac.dbmigration.core.main.MigrationResult; import com.robertvokac.dbmigration.core.main.MigrationResult;