Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

strange File::Copy issue

by danmcb (Monk)
on Oct 31, 2011 at 02:57 UTC ( [id://934812]=perlquestion: print w/replies, xml ) Need Help??

danmcb has asked for the wisdom of the Perl Monks concerning the following question:

I am writing a wma to mp3 converter, which preserves tags by using Audio::WMA and MP3::Tag

towards the end of the code, I have this:

$mp3->update_tags( $mp3_tags ); # write tags to tmp.mp3 . . copy( 'tmp.mp3', $target);

(I am using File::Copy copy because some files have all kinds of quotes and so on which make backticks, system, etc awkward. I guess I could have escaped them, but I went this way instead ... that's what modules are for, right?)

Here's the weird thing. My target file (in this case test.mp3) doesn't have tags, but tmp.mp3 does. the files are also a bit different in size:

root@trekulbollox:~/convert_wma# ls -l total 57864 -rwxr-x--- 1 root root 2595 2011-10-31 03:37 convert_wma.pl -rw-r--r-- 1 root root 0 2011-10-31 03:37 errors -rwxr-xr-x 1 root root 9913921 2011-10-31 03:01 original.wma -rw-r--r-- 1 root root 24627199 2011-10-31 03:38 test.mp3 -rw-r--r-- 1 root root 24627327 2011-10-31 03:38 tmp.mp3 root@trekulbollox:~/convert_wma# id3v2 -l tmp.mp3 id3v1 tag info for tmp.mp3: Title : Big Foot Artist: Stephen Riley Album : Easy to Remember Year: 2007, Genre: Jazz (8) Comment: Track: 2 tmp.mp3: No ID3v2 tag root@trekulbollox:~/convert_wma# id3v2 -l test.mp3 test.mp3: No ID3 tag

There is really nothing between the writing of tags and the copy that can do this. Is it possible that there is some kind of weird timing issue, where the tag is not flushed to the file before the copy happens?

I am sitting here thinking this must be a late night issue ... but there are no file operations at all between the two points. What is going on ... ?

Replies are listed 'Best First'.
Re: strange File::Copy issue
by mbethke (Hermit) on Oct 31, 2011 at 03:52 UTC
    Have you closed the file after writing to it? Writes are probably buffered so they may not have been flushed to disk. If there is no explicit close method, try undefing the $mp3 object.

      Good advice. Just wanted to add that MP3::Tag does have $mp3->close; for this purpose.

Re: strange File::Copy issue
by johnny_carlos (Scribe) on Oct 31, 2011 at 03:46 UTC
    Try adding: or die "Copy failed: $!", to your copy function. Perhaps it's choking on something and not telling you.
      Unfortunately, $! is not that much helpful with File::Copy; for instance, it doesn't say whether the error occurs when reading or writing the file.

      However, I consider it unlikely that the effect you are describing is due to a problem with Copy::File. I noticed that source- and target file in your example have the same modification time. Could it be that some other function in your program test.mp3, after it was copied? You could unlink test.mp3 before doing the copying (to clean up anything left from the previous test run), and do a system('ls -l *mp3') immediately after the call to copy().

      -- 
      Ronald Fischer <ynnor@mm.st>
Re: strange File::Copy issue
by JavaFan (Canon) on Oct 31, 2011 at 09:39 UTC
    I am using File::Copy copy because some files have all kinds of quotes and so on which make backticks, system, etc awkward. I guess I could have escaped them, but I went this way instead ... that's what modules are for, right?
    What's awkward about
    system "cp", 'tmp.mp3', $target and die;
    ? It doesn't matter how many quotes $target has, as there's nothing that will be interpreting the quotes.

    There may be reasons to use File::Copy, but "quotes in file names" isn't one of them.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://934812]
Approved by lidden
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2024-03-28 23:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found