void backup(final File root, final File backupLocation, final List<String> path, final List<ContentModification> rollback, final PatchingTaskContext context) throws IOException { if(!root.exists()) { // Perhaps an error condition? } else if(root.isDirectory()) { final File[] files = root.listFiles(); final String rootName = root.getName(); if(files == null || files.length == 0) { // Create empty directory rollback.add(createRollbackItem(rootName, path, NO_CONTENT, true)); } else { final List<String> newPath = new ArrayList<String>(path); newPath.add(rootName); for (File file : files) { final String name = file.getName(); final File newBackupLocation = new File(backupLocation, name); backup(file, newBackupLocation, newPath, rollback, context); } } } else { // Copy and record the backup action final byte[] hash = copy(root, backupLocation); rollback.add(createRollbackItem(root.getName(), path, hash, false)); } }
void backup(final File root, final File backupLocation, final List<String> path, final List<ContentModification> rollback, final PatchingTaskContext context) throws IOException { if(!root.exists()) { // Perhaps an error condition? } else if(root.isDirectory()) { final File[] files = root.listFiles(); final String rootName = root.getName(); if(files == null || files.length == 0) { // Create empty directory rollback.add(createRollbackItem(rootName, path, NO_CONTENT, true)); } else { final List<String> newPath = new ArrayList<String>(path); newPath.add(rootName); for (File file : files) { final String name = file.getName(); final File newBackupLocation = new File(backupLocation, name); backup(file, newBackupLocation, newPath, rollback, context); } } } else { // Copy and record the backup action final byte[] hash = copy(root, backupLocation); rollback.add(createRollbackItem(root.getName(), path, hash, false)); } }