bugGNU Core Utilities - Bugs: bug #24949, coreutils pwd not implementing...

 
 

You are not allowed to post comments on this tracker with your current authentication level.

bug #24949: coreutils pwd not implementing latest POSIX features

Submitter:  Paul D. Smith <psmith>
Submitted:  Wed 26 Nov 2008 08:50:44 PM UTC
   
 
Category:  None Severity:  3 - Normal
Item Group:  None Status:  Fixed
Privacy:  Public Assigned to:  ericb
Open/Closed:  Closed

Mon 23 Mar 2009 08:53:18 PM UTC, comment #3: 

How about the attached patch?

(file #17780)

Eric Blake <ericb>
Group administrator
Mon 01 Dec 2008 02:04:13 AM UTC, comment #2: 

The problem is that without -P I can't invoke pwd from things like Perl portably.  If I use "my $pwd = `pwd`;" and it runs a shell and uses the shell builtin version of pwd, then I get the wrong thing (I explicitly want the "real" path; what POSIX defines "pwd -P" to return).

But on the other hand, if I use "my $pwd = `pwd -P`;", which is what a correct POSIX-conforming script would do, and it runs coreutils pwd instead of a shell builtin, I get a syntax error.

In short, this is a big drag.

It would be great if, at least, coreutils pwd handled the -P option (since that's what it does by default it could just accept the option and behave as it does now).  In other words, I think Reuben Thomas's solution here: http://lists.gnu.org/archive/html/bug-coreutils/2008-10/msg00259.html is acceptable.

On the other hand, I think it would not actually be that difficult to implement -L.  It seems to me that Eric Blake's description of what it would take to adhere to the POSIX standard, as he describes here: http://lists.gnu.org/archive/html/bug-coreutils/2008-10/msg00258.html is more complicated than necessary.  We do not need to strip "." or ".." from the value of $PWD.  All we need to do is determine if the value of $PWD is (a) an absolute path, and (b) it refers to the current directory, and (c) it does not contain "." or ".." as filename elements.  Of these the only tricky bit AFAICS is (b); we would need to do something like compare the device/inode values of the directory pointed to by $PWD and the current directory to be sure they had the same value.  I'm not sure if glib provides this type of functionality.

If all those conditions are met, then "pwd" and "pwd -L" print the value of $PWD.  If any of those conditions are not met, or if the user asks for "pwd -P", then we print the absolute pathname determined the same way we determine it today.

Paul D. Smith <psmith>
Thu 27 Nov 2008 05:15:48 AM UTC, comment #1: 

This has been brought up repeatedly in the past; see this thread:

http://lists.gnu.org/archive/html/bug-coreutils/2008-10/msg00293.html

Eric Blake <ericb>
Group administrator
Wed 26 Nov 2008 08:50:44 PM UTC, original submission:  

I've noticed that in the POSIX standard (The Open Group Base Specifications Issue 6 IEEE Std 1003.1, 2004 Edition), the pwd utility is expected to take two options:


SYNOPSIS
    pwd [-L | -P ]

DESCRIPTION
    The pwd utility shall write to standard output an absolute pathame
    of the current working directory, which does not contain the
    filenames dot or dot-dot.

OPTIONS
    The pwd utility shall conform to the Base Definitions volume of
    IEEE Std 1003.1-2001, Section 12.2, Utility Syntax Guidelines.

    The following options shall be supported by the implementation:

    -L
        If the PWD environment variable contains an absolute pathname of
        the current directory that does not contain the filenames dot or
        dot-dot, pwd shall write this pathname to standard output.
        Otherwise, the -L option shall behave as the -P option.
    -P
        The absolute pathname written shall not contain filenames that,
        in the context of the pathname, refer to files of type symbolic
        link.

    If both -L and -P are specified, the last one shall apply. If
    neither -L nor -P is specified, the pwd utility shall behave as if
    -L had been specified.


It doesn't appear that the coreutils implementation of pwd supports this.

I realize that most shells including bash have a pwd builtin which is typically used when the user runs "pwd".  However, pwd is not required to be a shell builtin by POSIX, and so a strictly conforming sh implementation is not required to provide it.  It seems to me that coreutils "pwd" should conform.

What do you all think?  I can provide a patch if it would be something you're interested in.

Paul D. Smith <psmith>

 

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

Attached Files
file #17780:  coreutils.patch1 added by ericb (9KiB - application/octet-stream - First cut at 'pwd -L/-P')

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by ericb (Posted a comment)
  • -email is unavailable- added by psmith (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.

     

    Follow 5 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2009-05-19 ericb StatusIn Progress Fixed
        Open/ClosedOpen Closed
    2009-03-23 ericb StatusNone In Progress
        Assigned toNone ericb
    2009-03-23 ericb Attached File- Added coreutils.patch1, #17780

    Back to the top

    Powered by Savane 3.13-caa5.
    Corresponding source code