diff --git a/fotolib2/src/main/java/de/k3b/media/PhotoPropertiesBulkUpdateService.java b/fotolib2/src/main/java/de/k3b/media/PhotoPropertiesBulkUpdateService.java index a13a588f..39c77010 100644 --- a/fotolib2/src/main/java/de/k3b/media/PhotoPropertiesBulkUpdateService.java +++ b/fotolib2/src/main/java/de/k3b/media/PhotoPropertiesBulkUpdateService.java @@ -119,6 +119,12 @@ public PhotoPropertiesUpdateHandler applyChanges(IFile inFilePath, IFile outFile if (!sameFile || (changed != null)) { debugExif(sb, "assign ", exifHandler, inFilePath); + IFile jpgFileDir = null; + String jpgFileNameDeleted = null; + if (!sameFile && deleteOriginalWhenFinished) { + jpgFileDir = inFilePath.getParentFile(); + jpgFileNameDeleted = inFilePath.getName(); + } exifHandler.save("PhotoPropertiesUpdateHandler save"); @@ -129,7 +135,7 @@ public PhotoPropertiesUpdateHandler applyChanges(IFile inFilePath, IFile outFile inFilePath.setLastModified(lastModified); } - if (sb != null) { + if (sb != null && inFilePath.exists()) { PhotoPropertiesUpdateHandler exifVerify = PhotoPropertiesUpdateHandler.create(inFilePath, null, deleteOriginalWhenFinished, "dbg in PhotoPropertiesUpdateHandler", true, true, false); debugExif(sb, "new ", exifVerify, inFilePath); @@ -147,11 +153,12 @@ public PhotoPropertiesUpdateHandler applyChanges(IFile inFilePath, IFile outFile } } - if (!sameFile && deleteOriginalWhenFinished) { - IFile delete = XmpFile.getSidecar(inFilePath, false); + if (jpgFileNameDeleted != null) { + // jpg deleted: Also delete corresponding xmp-s if exist + IFile delete = XmpFile.getSidecar(jpgFileDir, jpgFileNameDeleted, false); deleteFile(delete); - delete = XmpFile.getSidecar(inFilePath, true); + delete = XmpFile.getSidecar(jpgFileDir, jpgFileNameDeleted, true); deleteFile(delete); delete = inFilePath; diff --git a/fotolib2/src/main/java/de/k3b/media/PhotoPropertiesUpdateHandler.java b/fotolib2/src/main/java/de/k3b/media/PhotoPropertiesUpdateHandler.java index 7d311baa..f9d2ef39 100644 --- a/fotolib2/src/main/java/de/k3b/media/PhotoPropertiesUpdateHandler.java +++ b/fotolib2/src/main/java/de/k3b/media/PhotoPropertiesUpdateHandler.java @@ -48,12 +48,12 @@ public class PhotoPropertiesUpdateHandler extends PhotoPropertiesWrapper implements IPhotoProperties, IPhotoPropertyFileWriter { private static final Logger logger = LoggerFactory.getLogger(LibGlobal.LOG_TAG); - private ExifInterfaceEx exif; // not null if exif changes are written to jpg file - private PhotoPropertiesXmpSegment xmp; // not null if exif changes are written to xmp sidecar file. + private final ExifInterfaceEx exif; // not null if exif changes are written to jpg file + private final PhotoPropertiesXmpSegment xmp; // not null if exif changes are written to xmp sidecar file. private IFile jpgInFile; // where changes are read from. private IFile jpgOutFile; // where changes are written to. Null meanst same as input private boolean deleteOriginalAfterFinish; // true: after save original jpg/mxp are deleted (move instead of copy) - private long dbgLoadEndTimestamp; + private long dbgLoadEndTimestamp; private PhotoPropertiesUpdateHandler( IPhotoProperties readChild, IPhotoProperties writeChild, @@ -108,6 +108,7 @@ protected static PhotoPropertiesUpdateHandler create( if (LibGlobal.debugEnabledJpgMetaIo) { startTimestamp = new Date().getTime(); } + PhotoPropertiesXmpSegment xmp = PhotoPropertiesXmpSegment.loadXmpSidecarContentOrNull(jpgInFile, dbg_context); if ((xmp == null) && (createXmpIfNotExist || PhotoPropertiesUtil.isImage(jpgInFile, PhotoPropertiesUtil.IMG_TYPE_COMPRESSED_NON_JPG | PhotoPropertiesUtil.IMG_TYPE_UNCOMPRESSED_NON_JPG))) {