I actually had Strawberry Perl on my Windows..

Though printing with catdir results in native backslashes, all the file
functions happily accept paths even in Unix style anyway.

C:\>perl -e "use File::Spec; print File::Spec->catdir('temp','test.txt')"
temp\test.txt

C:\>perl -e "use File::Spec; print File::Spec->catdir('C:','temp','test.txt')"
C:\temp\test.txt

C:\>perl -e "open(FOO, '/temp/test.txt') or die; print <FOO>"
foobar

C:\>perl -e "open(FOO, '\temp\test.txt') or die; print <FOO>"
foobar

C:\>perl -e "open(FOO, 'C:\temp\test.txt') or die; print <FOO>"
foobar

So kinda seems pointless trying to cater for the native way..


On Fri, Apr 29, 2022 at 07:46:50PM +0300, Henrik K wrote:
> 
> Ok it seems I'm going down the path of just doing stuff for the sake of
> "that's the way it's always been done"..
> 
> Does someone actually know why File::Spec->catdir (and catfile, which seems
> to work completely identically anyway) is used all over SpamAssassin?  Was
> it for some legacy Windows compatibility?  Does any Perl on Windows actually
> use native C:\Foo\Bar style paths that would require this method?  Does SA
> 4.0 even have any promise to work on Windows, and at what capacity? 
> Strawberry Perl?  Activestate Perl?  Cygwin?  WSL?  Why not just simplify
> code and ditch all the complicated to look and read File::Spec stuff..  you
> can also find many many examples where it is not used..  either it should be
> used 100% everywhere, or then there is no actual portability.
> 
> 
> On Fri, Apr 29, 2022 at 04:26:57PM -0000, h...@apache.org wrote:
> > Author: hege
> > Date: Fri Apr 29 16:26:57 2022
> > New Revision: 1900390
> > 
> > URL: http://svn.apache.org/viewvc?rev=1900390&view=rev
> > Log:
> > Purge write testfiles only sometimes, remember to use catdir
> > 
> > Modified:
> >     spamassassin/trunk/lib/Mail/SpamAssassin.pm
> > 
> > Modified: spamassassin/trunk/lib/Mail/SpamAssassin.pm
> > URL: 
> > http://svn.apache.org/viewvc/spamassassin/trunk/lib/Mail/SpamAssassin.pm?rev=1900390&r1=1900389&r2=1900390&view=diff
> > ==============================================================================
> > --- spamassassin/trunk/lib/Mail/SpamAssassin.pm (original)
> > +++ spamassassin/trunk/lib/Mail/SpamAssassin.pm Fri Apr 29 16:26:57 2022
> > @@ -1997,9 +1997,10 @@ sub set_global_state_dir {
> >  sub test_global_state_dir {
> >      my ($self, $dir) = @_;
> >      eval { mkpath($dir, 0, 0700); }; # just a single stat if exists already
> > -    # Purge stale test files
> > -    if (opendir(WT_DIR, $dir)) {
> > -      foreach (grep {/^\.sawritetest/ && (-M "$dir/$_"||0) > 0.0001} 
> > readdir(WT_DIR)) {
> > +    # Purge stale test files (enough to do only some times randomly)
> > +    if (rand() < 0.2 && opendir(WT_DIR, $dir)) {
> > +      foreach (grep {index($_, '.sawritetest') == 0 &&
> > +                 (-M File::Spec->catdir($dir, $_)||0) > 0.0001} 
> > readdir(WT_DIR)) {
> >          
> > unlink(Mail::SpamAssassin::Util::untaint_file_path(File::Spec->catdir($dir, 
> > $_)));
> >        }
> >        closedir WT_DIR;
> > 

Reply via email to