-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Restoring a Unix Backup on Windows is not working well (#147)
- Adds new command line options to --restore command to let the user select permission evaluation strategy - Implements a verification step during backup, to warn the user about potential file name case-insensitivity issues - Updates tests - Adds app banner - Updates readme Resolves #94 {minor} Signed-off-by: Esta Nagy <[email protected]>
- Loading branch information
Showing
17 changed files
with
431 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
.../src/main/java/com/github/nagyesta/filebarj/core/common/PermissionComparisonStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package com.github.nagyesta.filebarj.core.common; | ||
|
||
import com.github.nagyesta.filebarj.core.model.FileMetadata; | ||
import lombok.NonNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.Objects; | ||
import java.util.Optional; | ||
|
||
/** | ||
* Implements multiple strategies for comparing permissions. | ||
*/ | ||
public enum PermissionComparisonStrategy { | ||
|
||
/** | ||
* Compare permissions, owner and group names strictly. | ||
*/ | ||
STRICT { | ||
@Override | ||
public boolean matches( | ||
@NonNull final FileMetadata previousMetadata, | ||
@NonNull final FileMetadata currentMetadata) { | ||
return Objects.equals(previousMetadata.getPosixPermissions(), currentMetadata.getPosixPermissions()) | ||
&& Objects.equals(previousMetadata.getOwner(), currentMetadata.getOwner()) | ||
&& Objects.equals(previousMetadata.getGroup(), currentMetadata.getGroup()); | ||
} | ||
}, | ||
|
||
/** | ||
* Compare permissions only ignoring owner and group names. | ||
*/ | ||
PERMISSION_ONLY { | ||
@Override | ||
public boolean matches( | ||
@NonNull final FileMetadata previousMetadata, | ||
@NonNull final FileMetadata currentMetadata) { | ||
return Objects.equals(previousMetadata.getPosixPermissions(), currentMetadata.getPosixPermissions()); | ||
} | ||
}, | ||
|
||
/** | ||
* Only compare the first three characters of permissions, ignoring owner and group names. | ||
*/ | ||
RELAXED { | ||
private static final int FIRST_SIGNIFICANT_CHAR_INCLUSIVE = 0; | ||
private static final int LAST_SIGNIFICANT_CHAR_EXCLUSIVE = 3; | ||
@Override | ||
public boolean matches( | ||
@NonNull final FileMetadata previousMetadata, | ||
@NonNull final FileMetadata currentMetadata) { | ||
return Objects.equals(transform(previousMetadata.getPosixPermissions()), transform(currentMetadata.getPosixPermissions())); | ||
} | ||
|
||
@Nullable | ||
private static String transform(final String permissions) { | ||
return Optional.ofNullable(permissions) | ||
.map(s -> s.substring(FIRST_SIGNIFICANT_CHAR_INCLUSIVE, LAST_SIGNIFICANT_CHAR_EXCLUSIVE)) | ||
.orElse(null); | ||
} | ||
}, | ||
|
||
/** | ||
* Ignore permission and owner/group name differences. | ||
*/ | ||
IGNORE { | ||
@Override | ||
public boolean matches( | ||
@NonNull final FileMetadata previousMetadata, | ||
@NonNull final FileMetadata currentMetadata) { | ||
return true; | ||
} | ||
}; | ||
|
||
/** | ||
* Compares the permissions, owner name and group name. | ||
* | ||
* @param previousMetadata The previous metadata | ||
* @param currentMetadata The current metadata | ||
* @return true if the permissions are the same | ||
*/ | ||
public abstract boolean matches( | ||
@NonNull FileMetadata previousMetadata, | ||
@NonNull FileMetadata currentMetadata); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.