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

Should I be able to change the temporary directory? #5949

Closed
p6rt opened this issue Dec 30, 2016 · 4 comments
Closed

Should I be able to change the temporary directory? #5949

p6rt opened this issue Dec 30, 2016 · 4 comments

Comments

@p6rt
Copy link

@p6rt p6rt commented Dec 30, 2016

Migrated from rt.perl.org#130455 (status was 'resolved')

Searchable as RT130455$

@p6rt
Copy link
Author

@p6rt p6rt commented Dec 30, 2016

From @briandfoy

tmpdir doesn't appear to change directories. This is probably why I
had the problem with https://rt-archive.perl.org/perl6/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

@p6rt
Copy link
Author

@p6rt p6rt commented May 1, 2017

From @zoffixznet

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] rakudo/rakudo@b62d1a7
[2] Raku/roast@1d4e881

-- IO grant

@p6rt
Copy link
Author

@p6rt p6rt commented May 1, 2017

The RT System itself - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

@p6rt p6rt commented May 1, 2017

@zoffixznet - Status changed from 'open' to 'resolved'

@p6rt p6rt closed this May 1, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant