File::NCopy question

Discussion in 'Perl Misc' started by Christopher Benson-Manica, Sep 12, 2005.

  1. I'm trying to use File::NCopy::copy to preserve the modification time
    of a file, but I can't seem to get it to work. I've got, basically,

    use File::NCopy qw(copy);
    $fobj=File::NCopy->new(
    'force_write' => 1,
    'preserve' => 1,
    );
    $fobj->copy( "file1", "file2" );

    file2, however, is not keeping file1's modification time. I'm using
    ActiveState Perl version 5.8.7 on WinXP. Do I need to change
    'set_times'? Is there some other WinDoze quirk I need to be aware of
    to get this to work?

    --
    Christopher Benson-Manica | I *should* know what I'm talking about - if I
    ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
     
    Christopher Benson-Manica, Sep 12, 2005
    #1
    1. Advertising

  2. Christopher Benson-Manica wrote:
    > I'm trying to use File::NCopy::copy to preserve the modification time
    > of a file, but I can't seem to get it to work. I've got, basically,
    >
    > use File::NCopy qw(copy);
    > $fobj=File::NCopy->new(
    > 'force_write' => 1,
    > 'preserve' => 1,
    > );
    > $fobj->copy( "file1", "file2" );
    >
    > file2, however, is not keeping file1's modification time. I'm using
    > ActiveState Perl version 5.8.7 on WinXP. Do I need to change
    > 'set_times'? Is there some other WinDoze quirk I need to be aware of
    > to get this to work?


    Is the file that you are copying marked read-only? If so, the copy
    will also be read-only and the utime function that is called by NCopy
    to change the times ater the file is copied will fail (utime doesn't
    work on read-only files on Windows). If this is the case, remove the
    read-only attribute or override the utime function with the one
    provided in Win32API::File::Time that will work on read-only files.

    Robert Gamble
     
    Robert Gamble, Sep 12, 2005
    #2
    1. Advertising

  3. Robert Gamble <> wrote:

    > Is the file that you are copying marked read-only?


    No, but I imagine that I will have to make use of your suggestion once
    I do get whatever the underlying problem is resolved.

    > If so, the copy
    > will also be read-only and the utime function that is called by NCopy
    > to change the times ater the file is copied will fail (utime doesn't
    > work on read-only files on Windows). If this is the case, remove the
    > read-only attribute or override the utime function with the one
    > provided in Win32API::File::Time that will work on read-only files.


    So are those set_time and friends to copy just the Perl equivalent of
    function pointers? The documentation for ncopy really isn't clear on
    what those parameters are.

    --
    Christopher Benson-Manica | I *should* know what I'm talking about - if I
    ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
     
    Christopher Benson-Manica, Sep 12, 2005
    #3
  4. Christopher Benson-Manica wrote:
    > Robert Gamble <> wrote:
    >
    > > Is the file that you are copying marked read-only?

    >
    > No, but I imagine that I will have to make use of your suggestion once
    > I do get whatever the underlying problem is resolved.


    I couldn't duplicate your problem on WinXP Pro with ActiveState 5.8.7
    using NCopy versions 0.32 and 0.34. Could you confirm your version?
    Are you using something besides NTFS? You might want try using the
    perl utime function on your platform and see if it works on the files
    you are copying. There might also be a problem with the stat function
    on your system, check that too.

    > > If so, the copy
    > > will also be read-only and the utime function that is called by NCopy
    > > to change the times ater the file is copied will fail (utime doesn't
    > > work on read-only files on Windows). If this is the case, remove the
    > > read-only attribute or override the utime function with the one
    > > provided in Win32API::File::Time that will work on read-only files.

    >
    > So are those set_time and friends to copy just the Perl equivalent of
    > function pointers? The documentation for ncopy really isn't clear on
    > what those parameters are.


    Pretty much, we call them subroutine references in Perl though ;). If
    you take a look at the NCopy.pm file you will see how set_times is
    initialized to a reference to the File::NCopy::s_times subroutine.
    This sub stats the file being copied, gets the modification times, and
    then uses utime to update the copy. You can create your own subroutine
    and use the set_times option to use your sub instead. You could
    probably get away with just adding "use Win32API::File::Time
    qw(utime);" to the top of the NCopy.pm file.

    Robert Gamble
     
    Robert Gamble, Sep 12, 2005
    #4
  5. Robert Gamble <> wrote:

    > I couldn't duplicate your problem on WinXP Pro with ActiveState 5.8.7
    > using NCopy versions 0.32 and 0.34. Could you confirm your version?


    ppm>
    Querying target 1 (ActivePerl 5.8.7.813)
    1. File-NCopy [0.32] Copy file, file Copy file | dir, dir

    > Are you using something besides NTFS? You might want try using the
    > perl utime function on your platform and see if it works on the files
    > you are copying. There might also be a problem with the stat function
    > on your system, check that too.


    I'll try that.

    > This sub stats the file being copied, gets the modification times, and
    > then uses utime to update the copy. You can create your own subroutine
    > and use the set_times option to use your sub instead. You could
    > probably get away with just adding "use Win32API::File::Time
    > qw(utime);" to the top of the NCopy.pm file.


    I added it, and then got

    Can't locate Win32API/File/Time.pm in @INC (@INC contains: c:\bin\modules C:/Per l/lib C:/Perl/site/lib .) at C:/Perl/site/lib/File/NCopy.pm line 4.
    BEGIN failed--compilation aborted at C:/Perl/site/lib/File/NCopy.pm line 4.

    Is my installation broken?

    --
    Christopher Benson-Manica | I *should* know what I'm talking about - if I
    ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
     
    Christopher Benson-Manica, Sep 12, 2005
    #5
  6. Christopher Benson-Manica <> wrote in
    news:dg4p31$n34$:

    > Can't locate Win32API/File/Time.pm in @INC (@INC contains:
    > c:\bin\modules C:/Per l/lib C:/Perl/site/lib .) at
    > C:/Perl/site/lib/File/NCopy.pm line 4. BEGIN failed--compilation
    > aborted at C:/Perl/site/lib/File/NCopy.pm line 4.
    >
    > Is my installation broken?


    What makes you think so?

    ppm> s file-time
    Searching in Active Repositories
    1. Win32API-File-Time [0.005] Get and set file times in Windows -

    ppm> i 1

    Sinan
    --
    A. Sinan Unur <>
    (reverse each component and remove .invalid for email address)

    comp.lang.perl.misc guidelines on the WWW:
    http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
     
    A. Sinan Unur, Sep 12, 2005
    #6
  7. Robert Gamble <> wrote:

    > I couldn't duplicate your problem on WinXP Pro with ActiveState 5.8.7
    > using NCopy versions 0.32 and 0.34. Could you confirm your version?
    > Are you using something besides NTFS? You might want try using the
    > perl utime function on your platform and see if it works on the files
    > you are copying. There might also be a problem with the stat function
    > on your system, check that too.


    stat and utime seem to be fine - the following script works just fine:

    my( $mtime1 )=( stat "a.txt" )[9];
    my( $mtime2 )=( stat "b.txt" )[9];
    print( "mtime of a.txt=$mtime1\n" );
    print( "mtime of b.txt=$mtime2\n" );
    utime $mtime1,$mtime1,"b.txt";
    print( "after:\n" );
    my( $mtime1 )=( stat "a.txt" )[9];
    my( $mtime2 )=( stat "b.txt" )[9];
    print( "mtime of a.txt=$mtime1\n" );
    print( "mtime of b.txt=$mtime2\n" );

    I added some debug directly to s_times, and when it is finished the
    copied file has the correct modification time. However, when I check
    again immediately after copy() returns, it's wrong again, and
    different than what it was at the beginning of s_times. Does copy()
    do something else after preserving the file status that would cause
    the file to be "modified"?

    --
    Christopher Benson-Manica | I *should* know what I'm talking about - if I
    ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
     
    Christopher Benson-Manica, Sep 13, 2005
    #7
  8. Christopher Benson-Manica wrote:
    > Robert Gamble <> wrote:
    >
    > > I couldn't duplicate your problem on WinXP Pro with ActiveState 5.8.7
    > > using NCopy versions 0.32 and 0.34. Could you confirm your version?
    > > Are you using something besides NTFS? You might want try using the
    > > perl utime function on your platform and see if it works on the files
    > > you are copying. There might also be a problem with the stat function
    > > on your system, check that too.

    >
    > stat and utime seem to be fine - the following script works just fine:
    >
    > my( $mtime1 )=( stat "a.txt" )[9];
    > my( $mtime2 )=( stat "b.txt" )[9];
    > print( "mtime of a.txt=$mtime1\n" );
    > print( "mtime of b.txt=$mtime2\n" );
    > utime $mtime1,$mtime1,"b.txt";
    > print( "after:\n" );
    > my( $mtime1 )=( stat "a.txt" )[9];
    > my( $mtime2 )=( stat "b.txt" )[9];
    > print( "mtime of a.txt=$mtime1\n" );
    > print( "mtime of b.txt=$mtime2\n" );
    >
    > I added some debug directly to s_times, and when it is finished the
    > copied file has the correct modification time. However, when I check
    > again immediately after copy() returns, it's wrong again, and
    > different than what it was at the beginning of s_times. Does copy()
    > do something else after preserving the file status that would cause
    > the file to be "modified"?


    It shouldn't. Try running the following script on your machine:

    use File::NCopy qw(copy);
    $fobj=File::NCopy->new(
    'force_write' => 1,
    'preserve' => 1,
    );
    open(FILE, ">testfile1");
    close(FILE);
    my $mod_time1 = (stat "testfile1")[9];
    sleep 5;
    $fobj->copy( "testfile1", "testfile2" );
    my $mod_time2 = (stat "testfile2")[9];
    if ($mod_time1 == $mod_time2) {
    print "PASS\n";
    } else {
    print "FAIL\n";
    }

    On my WinXP box with AS Perl 5.8.7 build 813 with NCopy 0.32 is PASSes.
    If it FAILs on your machine, go to cpan.org, search for File::NCopy,
    download either version 0.32 or 0.34, extract the file called NCopy.pm
    and replace your current NCopy.pm file with it. If after doing this it
    still fails I'm at a loss (can you confirm you are using NTFS?). If
    this program prints PASS then you are doing something else in your
    program to modify the file.

    Robert Gamble
     
    Robert Gamble, Sep 13, 2005
    #8
  9. Robert Gamble <> wrote:

    > On my WinXP box with AS Perl 5.8.7 build 813 with NCopy 0.32 is PASSes.
    > If it FAILs on your machine, go to cpan.org, search for File::NCopy,
    > download either version 0.32 or 0.34, extract the file called NCopy.pm
    > and replace your current NCopy.pm file with it. If after doing this it
    > still fails I'm at a loss (can you confirm you are using NTFS?). If
    > this program prints PASS then you are doing something else in your
    > program to modify the file.


    Well, it passed, but I have no idea what the problem could be. I am
    settling for manually changing the file times as appropriate after
    copy(), since I've wasted too much time on this problem already :-|
    Thanks a lot for your very detailed help though!

    --
    Christopher Benson-Manica | I *should* know what I'm talking about - if I
    ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
     
    Christopher Benson-Manica, Sep 13, 2005
    #9
  10. Christopher Benson-Manica <> wrote in
    news:dg72ej$1vb$:

    > Robert Gamble <> wrote:
    >
    >> On my WinXP box with AS Perl 5.8.7 build 813 with NCopy 0.32 is
    >> PASSes.
    >> If it FAILs on your machine, go to cpan.org, search for File::NCopy,
    >> download either version 0.32 or 0.34, extract the file called
    >> NCopy.pm and replace your current NCopy.pm file with it. If after
    >> doing this it still fails I'm at a loss (can you confirm you are
    >> using NTFS?). If this program prints PASS then you are doing
    >> something else in your program to modify the file.

    >
    > Well, it passed, but I have no idea what the problem could be. I am
    > settling for manually changing the file times as appropriate after
    > copy(), since I've wasted too much time on this problem already :-|
    > Thanks a lot for your very detailed help though!


    If the module is not working out for you, and you have resort to those
    kinds of measures, have you considered using xcopy?

    Sinan

    --
    A. Sinan Unur <>
    (reverse each component and remove .invalid for email address)

    comp.lang.perl.misc guidelines on the WWW:
    http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
     
    A. Sinan Unur, Sep 13, 2005
    #10
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Luis Esteban Valencia Muñoz
    Replies:
    3
    Views:
    1,414
    Scott Allen
    Jun 4, 2005
  2. key9
    Replies:
    7
    Views:
    375
    Pete Becker
    Sep 13, 2006
  3. Dave
    Replies:
    1
    Views:
    996
    Juan T. Llibre
    Jun 8, 2007
  4. =?ISO-8859-2?Q?Miros=B3aw?= Makowiecki

    Reading of file by next of map file and by next of file descriptor.

    =?ISO-8859-2?Q?Miros=B3aw?= Makowiecki, Jul 10, 2007, in forum: C++
    Replies:
    1
    Views:
    795
    Alf P. Steinbach
    Jul 10, 2007
  5. Christopher Benson-Manica

    File::Copy works, File::NCopy doesn't

    Christopher Benson-Manica, Sep 13, 2005, in forum: Perl Misc
    Replies:
    4
    Views:
    201
    A. Sinan Unur
    Sep 14, 2005
Loading...

Share This Page