2 ###############################################################################
9 Attempts to invoke B<iconv> on the specified tracked file, placing the
10 output in [file].iconv
12 If given no other arguments, the invocation will lool like
16 iconv -f ISO-8859-1 -t UTF-8 -o <file>.utf8 <file>
20 otherwise, the arguments will be passed through like so
24 iconv [other arguments...] -o <file>.utf8 <file>
28 You'll need to invoke B<mig-add> prior to using commands like B<mig-iconv>
32 B<mig-iconv> <file> [other arguments...]
36 ###############################################################################
41 HOME PGHOST PGPORT PGUSER PGDATABASE MIGSCHEMA
42 MIGBASEWORKDIR MIGBASEGITDIR MIGGITDIR MIGWORKDIR
48 my $mig_bin = "$FindBin::Bin/";
49 use lib "$FindBin::Bin/";
52 pod2usage(-verbose => 2) if ! $ARGV[0] || $ARGV[0] eq '--help';
54 Mig::die_if_no_env_migschema();
55 Mig::die_if_mig_tracking_table_does_not_exist();
57 my $file = abs_path($ARGV[0]);
58 if ($file =~ /^$MIGBASEWORKDIR/) {
61 print "File falls outside of MIGWORKDIR ($MIGWORKDIR): $file\n";
66 ###############################################################################
69 my $file = abs_path(shift);
72 my $tracked_file_id = Mig::check_for_tracked_file($file);
73 if ($tracked_file_id) {
74 my $data = Mig::status_this_file($file);
75 print "iconv'ing tracked file: $file\n";
77 if (scalar(@args) == 0) {
87 system('iconv', @args, '-o', $file . '.utf8', $file);
88 system('touch', $file . '.utf8'); # handle 0-byte files
90 my $dbh = Mig::db_connect();
91 my $utf8_file = $dbh->quote($file . '.utf8');
92 if (! -e $file . '.utf8') {
93 print "utf8 file does not exist: $utf8_file\n";
94 $utf8_file = $dbh->quote('');
98 UPDATE $MIGSCHEMA.tracked_file
99 SET utf8_filename = $utf8_file
100 WHERE base_filename = " . $dbh->quote($file) . "
102 ") || die "Error inserting into table $MIGSCHEMA.tracked_file: $!\n";
103 Mig::db_disconnect($dbh);
105 print "File not currently tracked: $file\n";