From 510b531f8b1f876d59d9ee10f8f7d0ecc25ba204 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andreas=20Kusalananda=20K=C3=A4h=C3=A4ri?=
 <ak4@sanger.ac.uk>
Date: Tue, 22 May 2007 18:29:26 +0000
Subject: [PATCH] Do the right thing for HTTP files when --delete_downloaded
 and/or --cleanup is specified on the command line.

---
 .../xref_mapping/XrefParser/BaseParser.pm     | 20 ++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/misc-scripts/xref_mapping/XrefParser/BaseParser.pm b/misc-scripts/xref_mapping/XrefParser/BaseParser.pm
index cc52455a34..54c0f8bebf 100644
--- a/misc-scripts/xref_mapping/XrefParser/BaseParser.pm
+++ b/misc-scripts/xref_mapping/XrefParser/BaseParser.pm
@@ -483,12 +483,26 @@ sub fetch_files {
         } elsif ( $uri->scheme() eq 'http' ) {
             # Deal with HTTP files.
 
-            my $ua = LWP::UserAgent->new();
-            $ua->env_proxy();
-
             my $file_path =
               catfile( $dest_dir, basename( $uri->path() ) );
 
+            if ( $deletedownloaded && -f $file_path ) {
+                printf( "Deleting '%s'\n", $file_path );
+                unlink($file_path);
+            }
+
+            if ( $checkdownload && -f $file_path ) {
+                # The file is already there, no need to connect to a
+                # HTTP server.
+
+                printf( "File '%s' already exists\n", $file_path );
+                push( @processed_files, $file_path );
+                next;
+            }
+
+            my $ua = LWP::UserAgent->new();
+            $ua->env_proxy();
+
             if ( !-d dirname($file_path) ) {
                 printf( "Creating directory '%s'\n",
                         dirname($file_path) );
-- 
GitLab