aboutsummaryrefslogtreecommitdiffstats
path: root/fix_eol
diff options
context:
space:
mode:
authorGuillaume Rousse <guillomovitch@mandriva.org>2008-02-10 14:24:43 +0000
committerGuillaume Rousse <guillomovitch@mandriva.org>2008-02-10 14:24:43 +0000
commit7c291669bab5cf44b615a7073eb0752be7a44612 (patch)
tree7df29cadeddfb6419661e052ca933161d5e38c3a /fix_eol
parent0fd87f896eea780920497633ec02f2759e80ab89 (diff)
downloadspec-helper-7c291669bab5cf44b615a7073eb0752be7a44612.tar
spec-helper-7c291669bab5cf44b615a7073eb0752be7a44612.tar.gz
spec-helper-7c291669bab5cf44b615a7073eb0752be7a44612.tar.bz2
spec-helper-7c291669bab5cf44b615a7073eb0752be7a44612.tar.xz
spec-helper-7c291669bab5cf44b615a7073eb0752be7a44612.zip
name harmonization
Diffstat (limited to 'fix_eol')
-rwxr-xr-xfix_eol56
1 files changed, 56 insertions, 0 deletions
diff --git a/fix_eol b/fix_eol
new file mode 100755
index 0000000..c546fed
--- /dev/null
+++ b/fix_eol
@@ -0,0 +1,56 @@
+#!/usr/bin/perl
+# $Id$
+# convert end of line patterns from DOS to UNIX
+
+use strict;
+use warnings;
+use File::Find;
+use File::Temp;
+
+my $buildroot = $ENV{RPM_BUILD_ROOT};
+die "No build root defined" unless $buildroot;
+die "Invalid build root" unless -d $buildroot;
+# normalize build root
+$buildroot =~ s|/$||;
+
+my $exclude_pattern = join('|',
+ map { '(:?' . quotemeta($_) . ')' }
+ $ENV{EXCLUDE_FROM_EOL_CONVERSION} ?
+ split(' ', $ENV{EXCLUDE_FROM_EOL_CONVERSION}) : ()
+);
+$exclude_pattern = qr/$exclude_pattern/;
+
+find(\&convert, $buildroot);
+
+sub convert {
+ # skip symlinks
+ return if -l $_;
+ # skip directories
+ return if -d $_;
+ # skip binary files
+ return unless -T $_;
+ # skip excluded files
+ return if $File::Find::name =~ $exclude_pattern;
+
+ # check if first line has less than 80 characters and ends with \r\n
+ open(my $in, '<', $_) or die "Unable to open file $_: $!";
+ my $line = <$in>;
+ if (defined $line && length($line) <= 80 && $line =~ s/\r\n$/\n/) {
+ # process all file
+ my $out = File::Temp->new(DIR => '.', UNLINK => 0);
+ print $out $line;
+ while (defined ($line = <$in>)) {
+ $line =~ s/\r\n$/\n/;
+ print $out $line;
+ }
+ my $tmp = $out->filename;
+ $out = undef;
+
+ # rename file, taking care to keep original permissions
+ my $perms = (stat $_)[2] & 07777;
+ rename($tmp, $_) or die "Unable to rename $tmp to $_: $!";
+ chmod($perms, $_);
+ }
+
+ close($in);
+}