Problem reading file immediately after writing

Started by Joanna Carter, May 10, 2022, 06:12:14 AM

Previous topic - Next topic

Joanna Carter

Hi folks

I need to change the exif:orientation tag on a file and then, immediately, use a thumbnail generator to fetch the freshly rotated image.

At the moment, the only way I can get things to work is to introduce a delay immediately after writing.

I presume this is due to the overwriting of of the safety copy, etc.

Is there any way to get a callback when the safety stuff has completed?

This becomes even more problematic if I want to select multiple files.

Joanna Carter


StarGeek

This will require Phil's attention as it is beyond my knowledge.  I suspect he is having very good weather and is out birding.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

Joanna Carter

Quote
I suspect he is having very good weather and is out birding
I don't know - these part-time workers  ::) ;)

greybeard

You might need to share your code - just enough to show the problem

Joanna Carter

I doubt if that is going to help. It is written in Swift for a macOS app and it calls two functions in sequence...


            try? ExifWriter.writeOrientation(rotatedOrientation, for: [url])
           
            thumbnailItem.reloadImage()


The first function constructs and executes an ExifTool command line, the second function calls Apple's QLThumbnailGenerator to construct and return a thumbnail image.

Neither function is simple and showing their many lines of code is unlikely to reveal anything more.

Suffice to say that the second function needs to contain a call that delays the retrieval of the thumbnail in order to avoid the ExifTool command not having executed completely.


DispatchQueue.main.asyncAfter(deadline: .now() + 1)
    {
      ...


My guess is that ExifTool is tidying up the backup file on a background thread, but there appears to be no completion callback that I can hook into.

Joanna Carter

Hi folks

I've found the solution to the problem

Apple have now changed their Process class by deprecating the launch() function, which is asynchronous, and providing a completion handler, which is called after the process has fully run.

Happy days!!!

greybeard

#7
the Process terminationHandler should do what you need - I don't think this problem is specific to exiftool

Joanna Carter

You are absolutely right. It was something that I didn't find or need a couple of years ago when I started with this app.

Everything worked perfectly before because I had no need to reload the image until I added in the orientation code.

I have been using Xcode for many years and have published apps but, still, there is stuff that seems determined to hide from us as developers