[PATCH] Use File::Spec->rel2abs to sanitise output directory

dinkypumpkin dinkypumpkin at gmail.com
Wed Apr 6 17:12:11 EDT 2011


The patch below was proposed by Jon Davies here:

http://lists.infradead.org/pipermail/get_iplayer/2011-February/000803.html

I tested on Windows and determined that - as Jon suggested - File::Spec->rel2abs() 
would work on all platforms for sanitising the output directory path, so I have 
changed his code accordingly.  It also appears that Cwd::abs_path() 
(used on Linux/OSX for sanitising) behaves slightly differently on Windows, 
so it seems like a good idea to rationalise here.  The credit for this is Jon's, 
but if it breaks on your machine, the blame is mine.

Updated get_iplayer script is here:

https://github.com/dinkypumpkin/get_iplayer/raw/patched/get_iplayer

Commit history here:

https://github.com/dinkypumpkin/get_iplayer/commits/patched/

Patch follows -

get_iplayer uses Cwd::abs_path() to sanitise the output directory,
but this returns undef if the path doesn't exist.  This patch
substitutes Cwd::abs_path() with File::Spec->rel2abs(), which
does something similar, but successfully returns a path even if
it doesn't exist yet.  File::Spec->rel2abs() works in Windows,
so there is no longer a need for OS-specific sanitising of the
output directory.
---
 get_iplayer |    7 ++-----
 1 files changed, 2 insertions(+), 5 deletions(-)

diff --git a/get_iplayer b/get_iplayer
index 311ddaf..81d6dea 100755
--- a/get_iplayer
+++ b/get_iplayer
@@ -54,6 +54,7 @@ use Fcntl;
 use File::Copy;
 use File::Path;
 use File::stat;
+use File::Spec;
 use Getopt::Long;
 use HTML::Entities;
 use HTTP::Cookies;
@@ -4584,11 +4585,7 @@ sub generate_filenames {
 	}
 
 	# Determine direcotry and find it's absolute path
-	if ( $^O !~ /^MSWin32$/ ) {
-		$prog->{dir} = abs_path( $opt->{ 'output'.$prog->{type} } || $opt->{output} || $ENV{IPLAYER_OUTDIR} || '.' );
-	} else {
-		$prog->{dir} = $opt->{ 'output'.$prog->{type} } || $opt->{output} || $ENV{IPLAYER_OUTDIR} || '.';
-	}
+	$prog->{dir} = File::Spec->rel2abs( $opt->{ 'output'.$prog->{type} } || $opt->{output} || $ENV{IPLAYER_OUTDIR} || '.' );
 	
 	# Add modename to default format string if multimode option is used
 	$format .= ' <mode>' if $opt->{multimode};
-- 
1.7.4.3




More information about the get_iplayer mailing list