Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support File::Find / use Win32::LongPath::Globally; or Win32::LongPath -overridecore; so that CORE::chdir is chdirL #1

Closed
ghost opened this issue Dec 17, 2013 · 4 comments

Comments

@ghost
Copy link

ghost commented Dec 17, 2013

support File::Find / use Win32::LongPath::Globally; or Win32::LongPath -overridecore; so that CORE::chdir is chdirL

basically the idea is to have as first module use Win32::LongPath::Globally; and have File::Find WORK with unicode on NTFS transparently afterwards

stat/lstat don't work like Win32::Unicode::Native stat (list context),

I gave it a shot but I couldn't make it work (stat or chdir or readdir fails ... ), hopefully you'll have more clues :) thanks in advance

#!/usr/bin/perl --
BEGIN {
    if ( eval { require Win32; 1 } ) {
        require ex::override;
        require Win32::LongPath;
        ex::override->import(
            GLOBAL_lstat => sub(;*) {
                my $obj = &Win32::LongPath::lstatL;
                *_ = $obj; ## grrr
                wantarray
                  ? @{$obj}{
                    qw/ dev ino mode nlink uid gid rdev size atime mtime ctime blksize blocks /
                  }
                  : $obj
                  ; ## grr, copying Win32::Unicode::File::statW, that seemed to have worked
            },
            GLOBAL_stat => sub(;*) {
                my $obj = &Win32::LongPath::statL;
                *_ = $obj; ## grrr, nohelp
                wantarray
                  ? @{$obj}{
                    qw/ dev ino mode nlink uid gid rdev size atime mtime ctime blksize blocks /
                  }
                  : $obj
                  ; ## grr, copying Win32::Unicode::File::statW, that seemed to have worked
            },
            map( {
                    my $name        = $_;
                      my $prototype = prototype("CORE::$name");
                      "GLOBAL_$name" => eval
                      "sub($prototype){&Win32::LongPath::${name}L}";
                } qw/ chdir mkdir open readlink rename rmdir stat symlink unlink utime closedir opendir readdir /,
            )
        );
    }
}
package main;
use Data::Dump qw/ dd /;
use File::Find qw/ find /;
File::Find::find(
    {
        wanted => sub { ::dd( wanted => $File::Find::name , $_ ); },
        preprocess => sub { ::dd( preprocess => \@_ ); @_ },
        postprocess => sub { ::dd( postprocess => \@_ ); @_ },
    },
    q{some utf filenamed dir },
);  
exit( 0 );
@rdboisvert
Copy link
Owner

I understand what you are trying to do and I think I tried something similar way back when. It was difficult enough that I gave up and made the decision to work in parallel instead of using a total replacement.

If I have time in the next few weeks I will take this code and see if I can get any further.

Thanks for your efforts,
Bob

@rdboisvert
Copy link
Owner

Looking at the code I could redefine statL () and lstatL () to return an array in list context. However, openL (), opendirL (), closedirL (), and readdirL () will never be direct replacements for the matching core functions. Will this limited change satisfy your need?

@ghost ghost assigned rdboisvert Dec 17, 2013
@ghost
Copy link
Author

ghost commented Dec 18, 2013

Will this limited change satisfy your need?

its welcome but not really :)
I didn't realize opendirL/closedirL/readdirL are all methods of a Win32::LongPath object
this makes for a strange vocabulary , mixing oop and functional in an odd way
I really think its good to match the API where ever possible, especially when using the same names
The idea is for you to finish what I started and make it part of your distribution like Win32::Unicode::Native does :) You can borrow more ideas, like that whole blessed globs thing ...makes cooperation with autodie work (something to think about later)

sub opendir(*$) {
    my $dh = Win32::LongPath->new;
    return unless $dh->opendirL($_[1]);
    return $_[0] = $dh; ## copying Win32::Unicode::Native::opendir here
}

so thanks for your time, whatever you decide :) i'll try to make it work some more with File::Find later, Thanks again, bye

@rdboisvert
Copy link
Owner

Closing this issue since I am unable to satisfy this request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant