bugGNU Octave - Bugs: bug #43426, run doesn't return to original...

 
 

bug #43426: run doesn't return to original working directory if using relative path

Submitter:  Andreas Weber <andy1978>
Submitted:  Thu 16 Oct 2014 11:47:55 AM UTC
   
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Regression
Status:  Fixed Assigned to:  None
Originator Name:  Open/Closed:  * Closed
Release:  * dev Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Mon 27 Oct 2014 04:16:35 AM UTC, comment #8: 

I checked in a fix here (http://hg.savannah.gnu.org/hgweb/octave/rev/a834b3151c7e).  Instead of creating a third variable holding a directory name I used canonicalize_file_name() to make the relative directory name into an absolute one.  With this in place strcmp to pwd works because pwd() also returns an absolute name.

I also renamed the original directory startdir instead of wd to be a little clearer.

Rik <rik5>
Group administrator
Sat 18 Oct 2014 06:49:18 PM UTC, comment #7: 

bc_pwd was b(efore)c(all to script)_pwd. Sorry, I'm not good at creating meaningfull var names :-). script_directory is much better.

Andreas Weber <andy1978>
Group Member
Sat 18 Oct 2014 05:45:14 PM UTC, comment #6: 

Ok. I understand now.


show_runbug

ans =

/Users/bpabbott/Downloads/bug_43426/dir1

hello world

ans =

/Users/bpabbott/Downloads/bug_43426/dir1

hello world with cd ~

ans =

/Users/bpabbott


What does the "bc_pwd" mean?  Should we use something more clear? Something like "script_directory" or something else?

Ben Abbott <bpabbott>
Group Member
Sat 18 Oct 2014 05:00:28 PM UTC, comment #5: 

Yes, I try to mimic that Matlab behaviour which you describe in comment #4. Sorry If I was unclear.

When run("dir1/file.m") is called, the working directory is changed to dir1 before file.m gets executed.

If the script called with run doesn't change the working directory (pwd before and pwd after call of script are equal) then the working directory previous to run should be restored.

I've attached another test case to show this better. The first and second output should show the path where show_runbug.m resides in, the third should show your home dir.

(Btw, I accidentally left "keyboard" in the pasted code snippet :-D )

Andreas Weber <andy1978>
Group Member
Sat 18 Oct 2014 04:20:58 PM UTC, comment #4: 

Ok. I understand your point, but it appears that Matlab returns to the original working directory.


>> show_runbug

ans =

/Users/bpabbott/Downloads/runbug/mytest

hello world

ans =

/Users/bpabbott/Downloads/runbug/mytest


Ben Abbott <bpabbott>
Group Member
Sat 18 Oct 2014 03:46:23 PM UTC, comment #3: 

I think this won't work. The idea is to check if the called script (line 66) has changed the current working dir and only return to the old pwd (=wd) is not.

I would suggest

  wd = pwd ();
  unwind_protect
    cd (d);
    bc_pwd = pwd ();
    evalin ("caller", sprintf ('source ("%s%s");', f, ext),
            "rethrow (lasterror ())");
  unwind_protect_cleanup
    keyboard
    if (strcmp (bc_pwd, pwd ()))
      cd (wd);
    endif
  end_unwind_protect


Andreas Weber <andy1978>
Group Member
Sat 18 Oct 2014 03:32:35 PM UTC, comment #2: 

Proposed change set is attached. Should this be applied to default or gui-release?

(file #32295)

Ben Abbott <bpabbott>
Group Member
Sat 18 Oct 2014 12:30:26 PM UTC, comment #1: 

If I understand the intent of the if-block, the fix below should work, correct?


        if (! strcmp (wd, pwd ()))
          cd (wd);
        endif


Ben Abbott <bpabbott>
Group Member
Thu 16 Oct 2014 11:47:55 AM UTC, original submission:  

Since cset http://hg.savannah.gnu.org/hgweb/octave/rev/1363d909c577 (for bug #41543) run doesn't return back to the original working directory if using a relative path.

See attached archive and run "show_runbug.m" (run('../doit.m')) in octave. The path isn't changed back because there is a comparison

  if (strcmp (d, pwd ()))
    cd (wd);
  endif


and d is "..". I first thought it would be simple as changing this to

  if (strcmp ( make_absolute_filename (d), pwd ()))


but make_absolute_filename("..") returns a trailing "/" which pwd () doesn't.


Andreas Weber <andy1978>
Group Member

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files
file #32297:  ChangeSet.patch added by bpabbott (900B - application/octet-stream - changeset in Andreas Weber's name)
file #32296:  bug43426.tar.gz added by andy1978 (258B - application/gzip)
file #32295:  changeset.patch added by bpabbott (801B - application/octet-stream)
file #32281:  runbug.tar.gz added by andy1978 (227B - application/x-gzip)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by bpabbott (Posted a comment)
  • -email is unavailable- added by andy1978 (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 8 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2014-10-27 rik5 StatusPatch Submitted Fixed
        Open/ClosedOpen Closed
    2014-10-18 bpabbott Attached File- Added ChangeSet.patch, #32297
    2014-10-18 andy1978 Attached File- Added bug43426.tar.gz, #32296
    2014-10-18 bpabbott Attached File- Added changeset.patch, #32295
        CategoryNone Octave Function
        StatusNone Patch Submitted
    2014-10-16 andy1978 Attached File- Added runbug.tar.gz, #32281

    Back to the top

    Powered by Savane 3.13-d3ae.
    Corresponding source code