LibreCat / Catmandu-BagIt

Catmandu module for working with BagIt packages
Other
1 stars 1 forks source link

Add method in Catmandu::Exporter::BagIt failing because of getting status 304 (Not Modified) #17

Open snorri opened 7 months ago

snorri commented 7 months ago

In the add method a temporary file is created:

            my $tmp = Path::Tiny->tempfile
                    or Catmandu::Error->throw("Could not create temp file");

            # For now using a simplistic mirror operation
            my $fname    = $tmp->stringify;

And then there is a call to a mirror method of the user agent:

        my $response = $bagit->user_agent->mirror($url,$fname);

But the problem is that the mirror method will compare the modification time of the file on the server to the newly created temporary file and not fetch the file if the local file (the temp file) is newer, which it is always will be, since it was created just before. So it will never work to fetch the file, resulting in errors like: Failed to mirror https://server.com/x/y/z.pdf to /tmp/qQTuKQcvMq : 304 304 I don't see any way to fix this except to change the code. It seems problematic to use the mirror call for newly created file. Am I misunderstanding something? Is there some other way to make it work? As a temporary workaround, I changed the code locally and set the modification time of the temporary file directly to 0 before the mirror call. This will force the file to be fetched:

            #set access and modification time to 0, so mirroring will work:
            my $touch_obj = File::Touch->new(
                 time => 0,
            );
            $touch_obj->touch($fname);

After this change everything works for us and the files are fetched.

phochste commented 6 months ago

version 0.2.51 is on its way to cpan