Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SNAP-3777_product_library #476

Open
wants to merge 1 commit into
base: 11.x
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ public class DataAccess {
add(".png"); add(".bmp"); add(".gif");
}};

private static final String[] DIRECTORY_BASED_PRODUCTS_EXTENSIONS = new String[]{
".xml",
".dim",
".safe"
};

public static boolean databaseInitialised = false;

private static H2DatabaseParameters dbParams;
Expand Down Expand Up @@ -565,7 +571,7 @@ static SaveProductData saveLocalProduct(Product localProductToSave, BufferedImag
Path relativePath = extractProductPathRelativeToLocalRepositoryFolder(productPath, localRepositoryFolder.getPath());

FileTime fileTime = Files.getLastModifiedTime(productPath);
long sizeInBytes = computeFileSize(localProductToSave, productPath);
long sizeInBytes = computeFileSize(productPath);
productId = getProductId(localRepositoryFolder.getId(), relativePath);
if (productId == null) {
productId = insertProduct(localProductToSave, polygon2D, relativePath, localRepositoryFolder.getId(), fileTime, sizeInBytes, connection);
Expand Down Expand Up @@ -1172,14 +1178,13 @@ private static boolean existsTable(String tableName) throws SQLException {
}
}

private static long computeFileSize(Product product, Path productPath) throws IOException {
private static long computeFileSize(Path productPath) throws IOException {
final Path computedPath;
final String extension = FileUtils.getExtension(productPath.toString());
if (ZipUtils.isZipped(productPath) || (extension != null && SIMPLE_PRODUCT_EXTENSIONS.contains(extension.toLowerCase()))) {
computedPath = productPath;
} else {
final String[] formatNames = product.getProductReader().getReaderPlugIn().getFormatNames();
if (Arrays.stream(formatNames).anyMatch(f -> f.startsWith("GeoTIFF"))) {
if (Arrays.stream(DIRECTORY_BASED_PRODUCTS_EXTENSIONS).noneMatch(f -> f.toLowerCase().endsWith(extension))) {
computedPath = productPath;
} else {
computedPath = productPath.getParent();
Expand Down