| 1 | #!/usr/bin/perl |
|---|
| 2 | |
|---|
| 3 | # Check whether there are naming conflicts when names are truncated to |
|---|
| 4 | # the DOSish case-ignoring 8.3 format, plus other portability no-nos. |
|---|
| 5 | |
|---|
| 6 | # The "8.3 rule" is loose: "if reducing the directory entry names |
|---|
| 7 | # within one directory to lowercase and 8.3-truncated causes |
|---|
| 8 | # conflicts, that's a bad thing". So the rule is NOT the strict |
|---|
| 9 | # "no filename shall be longer than eight and a suffix if present |
|---|
| 10 | # not longer than three". |
|---|
| 11 | |
|---|
| 12 | # TODO: this doesn't actually check for *directory entries*, what this |
|---|
| 13 | # does is to check for *MANIFEST entries*, which are only files, not |
|---|
| 14 | # directories. In other words, a 8.3 conflict between a directory |
|---|
| 15 | # "abcdefghx" and a file "abcdefghy" wouldn't be noticed-- or even for |
|---|
| 16 | # a directory "abcdefgh" and a file "abcdefghy". |
|---|
| 17 | |
|---|
| 18 | sub eight_dot_three { |
|---|
| 19 | my ($dir, $base, $ext) = ($_[0] =~ m!^(?:(.+)/)?([^/.]+)(?:\.([^/.]+))?$!); |
|---|
| 20 | my $file = $base . defined $ext ? ".$ext" : ""; |
|---|
| 21 | $base = substr($base, 0, 8); |
|---|
| 22 | $ext = substr($ext, 0, 3) if defined $ext; |
|---|
| 23 | if ($dir =~ /\./) { |
|---|
| 24 | warn "$dir: directory name contains '.'\n"; |
|---|
| 25 | } |
|---|
| 26 | if ($file =~ /[^A-Za-z0-9\._-]/) { |
|---|
| 27 | warn "$file: filename contains non-portable characters\n"; |
|---|
| 28 | } |
|---|
| 29 | if (length $file > 30) { |
|---|
| 30 | warn "$file: filename longer than 30 characters\n"; # make up a limit |
|---|
| 31 | } |
|---|
| 32 | if (defined $dir) { |
|---|
| 33 | return ($dir, defined $ext ? "$dir/$base.$ext" : "$dir/$base"); |
|---|
| 34 | } else { |
|---|
| 35 | return ('.', defined $ext ? "$base.$ext" : $base); |
|---|
| 36 | } |
|---|
| 37 | } |
|---|
| 38 | |
|---|
| 39 | my %dir; |
|---|
| 40 | |
|---|
| 41 | if (open(MANIFEST, "MANIFEST")) { |
|---|
| 42 | while (<MANIFEST>) { |
|---|
| 43 | chomp; |
|---|
| 44 | s/\s.+//; |
|---|
| 45 | unless (-f) { |
|---|
| 46 | warn "$_: missing\n"; |
|---|
| 47 | next; |
|---|
| 48 | } |
|---|
| 49 | if (tr/././ > 1) { |
|---|
| 50 | print "$_: more than one dot\n"; |
|---|
| 51 | next; |
|---|
| 52 | } |
|---|
| 53 | my ($dir, $edt) = eight_dot_three($_); |
|---|
| 54 | ($dir, $edt) = map { lc } ($dir, $edt); |
|---|
| 55 | push @{$dir{$dir}->{$edt}}, $_; |
|---|
| 56 | } |
|---|
| 57 | } else { |
|---|
| 58 | die "$0: MANIFEST: $!\n"; |
|---|
| 59 | } |
|---|
| 60 | |
|---|
| 61 | for my $dir (sort keys %dir) { |
|---|
| 62 | for my $edt (keys %{$dir{$dir}}) { |
|---|
| 63 | my @files = @{$dir{$dir}->{$edt}}; |
|---|
| 64 | if (@files > 1) { |
|---|
| 65 | print "@files: directory $dir conflict $edt\n"; |
|---|
| 66 | } |
|---|
| 67 | } |
|---|
| 68 | } |
|---|