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

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

Open
snorri opened this issue Jan 23, 2024 · 1 comment

Comments

@snorri
Copy link
Member

snorri commented Jan 23, 2024

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 added a commit that referenced this issue Jan 31, 2024
@phochste
Copy link
Member

version 0.2.51 is on its way to cpan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants