Skip Menu |
Report information

Subject: Should I be able to change the temporary directory?
From: brian d foy <brian.d.foy [...] gmail.com>
Date: Fri, 30 Dec 2016 03:34:11 -0500
To: rakudobug [...] perl.org
Download (untitled) / with headers
text/plain 3.1k
tmpdir doesn't appear to change directories. This is probably why I had the problem with https://rt.perl.org/Ticket/Display.html?id=130454 (although I should have had a different error there). It's not documented to do that in the various IO::Spec modules, but I was trying stuff in S16 to see what works. Should I be able to change the temporary directory as S16 says, or is it forever fixed and should be documented as read-only? my $dir = '/Users/brian'; my $dir-io = $dir.IO; put "$dir is a dir: " ~ $dir-io.d; put "$dir is readable: " ~ $dir-io.r; put "$dir is executable: " ~ $dir-io.x; put "$dir is writeable: " ~ $dir-io.w; tmpdir( $dir ) It looks like everything should work, but it doesn't: /Users/brian is a dir: True /Users/brian is readable: True /Users/brian is executable: True /Users/brian is writeable: True Cannot modify an immutable IO::Path in block <unit> at /Volumes/Big Scratch/Dropbox/~~Writing/Perl Writing/LearningPerl6/learning_perl_6/scratch/file_trials.p6 line 11 Or, assigning to it directly: my $dir = '/Users/brian'; my $dir-io = $dir.IO; put "$dir is a dir: " ~ $dir-io.d; put "$dir is readable: " ~ $dir-io.r; put "$dir is executable: " ~ $dir-io.x; put "$dir is writeable: " ~ $dir-io.w; $*TMPDIR = $dir; It says I can't assign to $*TMPDIR. How is it that I can't assign to dynamic variable? What's the point of it being dynamic if it can't change? Cannot modify an immutable IO::Path in block <unit> at /Volumes/Big Scratch/Dropbox/~~Writing/Perl Writing/LearningPerl6/learning_perl_6/scratch/file_trials.p6 line 11 Try it with my: my $dir = '/Users/brian'; my $dir-io = $dir.IO; put "$dir is a dir: " ~ $dir-io.d; put "$dir is readable: " ~ $dir-io.r; put "$dir is executable: " ~ $dir-io.x; put "$dir is writeable: " ~ $dir-io.w; my $*TMPDIR; tmpdir( $dir ) Now it's a different sort of error. This kinda makes sense because there's nothing in $*TMPDIR and tmpdir expects IO::Spec. But why is the error in chdir and not something that catches that the argument wasn't IO::Spec? /Users/brian is a dir: True /Users/brian is readable: True /Users/brian is executable: True /Users/brian is writeable: True No such method 'chdir' for invocant of type 'Any' in block <unit> at /Volumes/Big Scratch/Dropbox/~~Writing/Perl Writing/LearningPerl6/learning_perl_6/scratch/file_trials.p6 line 13 Use temp instead, and it's a different error (despite that temp was used for this purpose in S16): my $dir = '/Users/brian'; my $dir-io = $dir.IO; put "$dir is a dir: " ~ $dir-io.d; put "$dir is readable: " ~ $dir-io.r; put "$dir is executable: " ~ $dir-io.x; put "$dir is writeable: " ~ $dir-io.w; temp $*TMPDIR; tmpdir( $dir ) Now it's a different sort of error: /Users/brian is a dir: True /Users/brian is readable: True /Users/brian is executable: True /Users/brian is writeable: True Can only use 'temp' on a container in block <unit> at /Volumes/Big Scratch/Dropbox/~~Writing/Perl Writing/LearningPerl6/learning_perl_6/scratch/file_trials.p6 line 11
RT-Send-CC: perl6-compiler [...] perl.org
Download (untitled) / with headers
text/plain 1.1k
Thank you for the report. The issues in this ticket have been resolved: - "tmpdir doesn't appear to change directories" - &tmpdir has been removed - "Should I be able to change the temporary directory" - Yes, by assigning to $*TMPDIR directly; simply do `my $*TMPDIR = 'foo/bar'.IO`. The issue that blocked assignment was fixed[^1] and tested[^2] in 2017.04 release - "Can only use 'temp' on a container" - This too was fixed[^1] and tested[^2] in 2017.04 release Side note: - "What's the point of it being dynamic if it can't change?" - There's no connection between dynamics and the ability to change them. Their point is scoping and not mutability; a change done to a dynamic var in some sub would still be visible up the call stack, which is why you'd usually use a `temp` or `my` on these global dynamic variables, like $*TMPDIR, to prevent your changes affecting other stuff. We do have immutable (or rather, containerless) dynamics (e.g. $*THREAD) and being unable to assign to them isn't a bug. [1] https://github.com/rakudo/rakudo/commit/b62d1a7 [2] https://github.com/perl6/roast/commit/1d4e881 -- IO grant


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

For issues related to this RT instance (aka "perlbug"), please contact perlbug-admin at perl.org