GNU bug report logs - #33255
27.0.50; expand-file-name: default directory expanded twice if relative

Previous Next

Package: emacs;

Reported by: immerrr again <immerrr <at> gmail.com>

Date: Sun, 4 Nov 2018 10:56:02 UTC

Severity: minor

Fixed in version 27.0.50

Done: Paul Eggert <eggert <at> cs.ucla.edu>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 33255 in the body.
You can then email your comments to 33255 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#33255; Package emacs. (Sun, 04 Nov 2018 10:56:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to immerrr again <immerrr <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Sun, 04 Nov 2018 10:56:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: immerrr again <immerrr <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 27.0.50;
 expand-file-name: default directory expanded twice if relative
Date: Sun, 4 Nov 2018 11:54:49 +0100
I have recently tried to play with a clean .emacs.d directory by setting
HOME=clean/home/dir, but faced an error coming from deep inside
package-install. The error boils down to the fact that
`expand-file-name' for some reason doubles the `default-directory'
prefix when it is relative:


$ emacs -Q -batch --eval '(let ((default-directory "DEFAULT-DIR/"))
(print (expand-file-name "EXPANDED-DIR/")))'

"DEFAULT-DIR/DEFAULT-DIR/EXPANDED-DIR/"


Interestingly, if you run `expand-file-name' twice you end up with four
prefixes:


$ emacs -Q -batch --eval '(let ((default-directory "DEFAULT-DIR/"))
(print (expand-file-name (expand-file-name "EXPANDED-DIR/"))))'

"DEFAULT-DIR/DEFAULT-DIR/DEFAULT-DIR/DEFAULT-DIR/EXPANDED-DIR/"


I couldn't find any requirement for DEFAULT-DIRECTORY parameter or
`default-directory' variable to be absolute, so I would assume this is a
bug in expand-file-name.


In GNU Emacs 27.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.18.9)
 of 2018-07-09 built on mmrcomp
Repository revision: 3307353e13a9226d477c9b1a39baae76584b90b9
Windowing system distributor 'The X.Org Foundation', version 11.0.11906000
System Description: Ubuntu 16.04.5 LTS

Recent messages:
Mark set
Saving file /home/immerrr/.cask/cask-cli.el...
Wrote /home/immerrr/.cask/cask-cli.el
Saving file /home/immerrr/.cask/cask-cli.el...
Wrote /home/immerrr/.cask/cask-cli.el
Saving file /home/immerrr/.cask/cask-cli.el...
Wrote /home/immerrr/.cask/cask-cli.el
Saving file /home/immerrr/.cask/cask-cli.el...
Wrote /home/immerrr/.cask/cask-cli.el
Mark set

Configured using:
 'configure --prefix=/home/immerrr/.local'

Configured features:
XPM JPEG TIFF GIF PNG RSVG IMAGEMAGICK SOUND GPM DBUS GSETTINGS NOTIFY
LIBSELINUX GNUTLS LIBXML2 FREETYPE M17N_FLT LIBOTF XFT ZLIB
TOOLKIT_SCROLL_BARS GTK3 X11 THREADS JSON LCMS2

Important settings:
  value of $LC_TIME: en_GB.UTF-8
  value of $LANG: en_US.UTF-8
  value of $XMODIFIERS: @im=ibus
  locale-coding-system: utf-8-unix

Major mode: el

Minor modes in effect:
  magit-auto-revert-mode: t
  auto-revert-mode: t
  global-git-commit-mode: t
  async-bytecomp-package-mode: t
  global-undo-tree-mode: t
  undo-tree-mode: t
  diff-auto-refine-mode: t
  nameless-mode: t
  guide-key-mode: t
  whitespace-mode: t
  flycheck-mode: t
  shell-dirtrack-mode: t
  counsel-projectile-mode: t
  projectile-mode: t
  ivy-mode: t
  global-company-mode: t
  company-mode: t
  pyvenv-mode: t
  paredit-mode: t
  auto-compile-on-save-mode: t
  auto-compile-mode: t
  recentf-mode: t
  yas-global-mode: t
  yas-minor-mode: t
  save-place-mode: t
  show-paren-mode: t
  global-display-line-numbers-mode: t
  display-line-numbers-mode: t
  override-global-mode: t
  bar-cursor-mode: t
  tooltip-mode: t
  global-eldoc-mode: t
  eldoc-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  size-indication-mode: t
  column-number-mode: t
  line-number-mode: t
  transient-mark-mode: t

Load-path shadows:
/home/immerrr/.emacs.d/elpa/ample-regexps-20151023.300/init-tryout
hides /home/immerrr/.emacs.d/elpa/lua-mode-20180104.626/init-tryout

Features:
(shadow sort mail-extr emacsbug sendmail macrostep-c cmacexp macrostep
cc-mode cc-fonts cc-guess cc-menus cc-cmds cc-styles cc-align cc-engine
cc-vars cc-defs ielm tar-mode git-rebase rect bug-reference py-isort
executable vc vc-dispatcher magit-bookmark magit-obsolete magit-blame
magit-stash magit-bisect magit-remote magit-commit magit-sequence
magit-notes magit-worktree magit-branch magit-collab ghub url-auth
magit-files magit-refs magit-status magit dired-x magit-repos
magit-apply magit-wip magit-log magit-diff smerge-mode magit-core
magit-autorevert autorevert filenotify magit-process magit-margin
magit-mode git-commit magit-git magit-section magit-utils ido crm
magit-popup log-edit message rfc822 mml mml-sec epa epg gnus-util rmail
rmail-loaddefs mailabbrev gmm-utils mailheader pcvs-util add-log
with-editor term ehelp esh-var esh-cmd esh-opt esh-io esh-ext esh-proc
esh-arg esh-groups eshell esh-module esh-mode async-bytecomp async
server imenu undo-tree diff edebug network-stream puny nsm rmc
company-jedi jedi-core epc ctable concurrent cap-words superword subword
pipenv f eieio-opt speedbar sb-image ezimage dframe warnings pulse
cl-print debug vc-git diff-mode bookmark pp company-elisp nameless
guide-key popwin face-remap disp-table whitespace flycheck find-func rx
jka-compr let-alist colir mmr-org-settings python tramp-sh tramp
trampver tramp-compat tramp-loaddefs ucs-normalize shell pcomplete
parse-time format-spec counsel-projectile projectile skeleton ibuf-macs
wgrep grep ibuf-ext ibuffer ibuffer-loaddefs counsel dired
dired-loaddefs compile esh-util swiper ivy-rich ivy delsel ivy-overlay
ffap thingatpt traad virtualenvwrapper gud comint ansi-color s
request-deferred request mail-utils url url-proxy url-privacy url-expand
url-methods url-history url-cookie url-domsuf url-util mailcap popup
python-environment deferred subr-x company-oddmuse company-keywords
company-etags etags xref project company-gtags company-dabbrev-code
company-dabbrev company-files company-capf company-cmake company-xcode
company-clang company-semantic company-eclim company-template
company-css company-nxml company-bbdb company pyvenv paredit
auto-compile packed recentf tree-widget wid-edit yasnippet derived
elec-pair saveplace hydra ring lv paren solarized-dark-theme
solarized-theme solarized color dash display-line-numbers
mmr-dir-local-env mmr-bootstrap quelpa-use-package cl-extra advice pcase
quelpa mm-decode mm-bodies mm-encode mail-parse rfc2231 rfc2047 rfc2045
mm-util ietf-drums mail-prsvr help-fns radix-tree help-mode
package-recipe-mode edmacro kmacro package-build-badges package-build
lisp-mnt use-package use-package-ensure use-package-delight
use-package-diminish use-package-bind-key use-package-core bind-key
diminish cl linum-ex bar-cursor easy-mmode mmr-minimal mmr-ediff
windmove time-date mule-util info finder-inf package easymenu epg-config
url-handlers url-parse auth-source cl-seq eieio eieio-core cl-macs
eieio-loaddefs password-cache json map url-vars seq byte-opt gv bytecomp
byte-compile cconv cl-loaddefs cl-lib tooltip eldoc electric uniquify
ediff-hook vc-hooks lisp-float-type mwheel term/x-win x-win
term/common-win x-dnd tool-bar dnd fontset image regexp-opt fringe
tabulated-list replace newcomment text-mode elisp-mode lisp-mode
prog-mode register page menu-bar rfn-eshadow isearch timer select
scroll-bar mouse jit-lock font-lock syntax facemenu font-core
term/tty-colors frame cl-generic cham georgian utf-8-lang misc-lang
vietnamese tibetan thai tai-viet lao korean japanese eucjp-ms cp51932
hebrew greek romanian slovak czech european ethiopic indian cyrillic
chinese composite charscript charprop case-table epa-hook jka-cmpr-hook
help simple abbrev obarray minibuffer cl-preloaded nadvice loaddefs
button faces cus-face macroexp files text-properties overlay sha1 md5
base64 format env code-pages mule custom widget hashtable-print-readable
backquote dbusbind inotify lcms2 dynamic-setting system-font-setting
font-render-setting move-toolbar gtk x-toolkit x multi-tty
make-network-process emacs)

Memory information:
((conses 16 1357726 145867)
 (symbols 48 50837 2)
 (miscs 40 6306 4056)
 (strings 32 121140 10207)
 (string-bytes 1 4278168)
 (vectors 16 68224)
 (vector-slots 8 1809895 106986)
 (floats 8 422 1779)
 (intervals 56 116849 2490)
 (buffers 992 53)
 (heap 1024 76825 5884))




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#33255; Package emacs. (Sun, 04 Nov 2018 12:28:02 GMT) Full text and rfc822 format available.

Message #8 received at 33255 <at> debbugs.gnu.org (full text, mbox):

From: Noam Postavsky <npostavs <at> gmail.com>
To: immerrr again <immerrr <at> gmail.com>
Cc: 33255 <at> debbugs.gnu.org
Subject: Re: bug#33255: 27.0.50;
 expand-file-name: default directory expanded twice if relative
Date: Sun, 04 Nov 2018 07:27:29 -0500
immerrr again <immerrr <at> gmail.com> writes:

> I have recently tried to play with a clean .emacs.d directory by setting
> HOME=clean/home/dir, but faced an error coming from deep inside
> package-install. The error boils down to the fact that
> `expand-file-name' for some reason doubles the `default-directory'
> prefix when it is relative:
[...]
> I couldn't find any requirement for DEFAULT-DIRECTORY parameter or
> `default-directory' variable to be absolute, so I would assume this is a
> bug in expand-file-name.

(elisp) File Name Expansion says:

 -- Variable: default-directory
     The value of this buffer-local variable is the default directory
     for the current buffer.  It should be an absolute directory name;
     it may start with `~'.[...]

And expand-file-name is supposed to expand file names relative to
default-directory, so if default-directory is itself relative I don't
see how it could possibly work.  So we should just mention the
absoluteness requirement in the docstring as well.

I think it would make sense for Emacs to expand HOME against the current
directory when it starts up, if HOME is relative.  That would let your
motivating example succeed without error.





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#33255; Package emacs. (Mon, 05 Nov 2018 00:59:01 GMT) Full text and rfc822 format available.

Message #11 received at 33255 <at> debbugs.gnu.org (full text, mbox):

From: Glenn Morris <rgm <at> gnu.org>
To: Noam Postavsky <npostavs <at> gmail.com>
Cc: 33255 <at> debbugs.gnu.org, immerrr again <immerrr <at> gmail.com>
Subject: Re: bug#33255: 27.0.50;
 expand-file-name: default directory expanded twice if relative
Date: Sun, 04 Nov 2018 19:58:01 -0500
Noam Postavsky wrote:

> immerrr again <immerrr <at> gmail.com> writes:
>
>> I have recently tried to play with a clean .emacs.d directory by setting
>> HOME=clean/home/dir,

I think a non-absolute HOME is a user error.
Eg cd $HOME may then not be idempotent.
I would use $PWD/clean/home/dir.

> I think it would make sense for Emacs to expand HOME against the current
> directory when it starts up, if HOME is relative.  

I would rather see Emacs abort with an error.
Otherwise you have to eg fix up process-environment too, else child
processes may behave oddly.




Reply sent to Paul Eggert <eggert <at> cs.ucla.edu>:
You have taken responsibility. (Tue, 13 Nov 2018 18:27:01 GMT) Full text and rfc822 format available.

Notification sent to immerrr again <immerrr <at> gmail.com>:
bug acknowledged by developer. (Tue, 13 Nov 2018 18:27:02 GMT) Full text and rfc822 format available.

Message #16 received at 33255-done <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Glenn Morris <rgm <at> gnu.org>
Cc: 33255-done <at> debbugs.gnu.org, immerrr again <immerrr <at> gmail.com>,
 Noam Postavsky <npostavs <at> gmail.com>
Subject: 27.0.50; expand-file-name: default directory expanded twice if
 relative
Date: Tue, 13 Nov 2018 10:26:43 -0800
[Message part 1 (text/plain, inline)]
> I think a non-absolute HOME is a user error.
> Eg cd $HOME may then not be idempotent.
That's true. However, POSIX says that sh treats ~/foo like $HOME/foo 
even when HOME is not absolute, and it's better if Emacs is consistent 
with POSIX as much as possible within the Emacs constraint that 
expand-file-name must expand to an absolute file name. So I implemented 
something along the line of Noam's suggestion by installing the attached 
patch into master; this should fix the bug originally reported.

Unlike Noam's suggestion, this patch causes Emacs to look at the current 
value of HOME, not the value HOME had when Emacs started up, as that 
corresponds more closely to POSIX sh.

[0001-Act-like-POSIX-sh-if-HOME-is-relative.patch (text/x-patch, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#33255; Package emacs. (Tue, 13 Nov 2018 20:14:01 GMT) Full text and rfc822 format available.

Message #19 received at 33255 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Paul Eggert <eggert <at> cs.ucla.edu>
Cc: 33255 <at> debbugs.gnu.org, immerrr <at> gmail.com
Subject: Re: bug#33255: 27.0.50;
 expand-file-name: default directory expanded twice if relative
Date: Tue, 13 Nov 2018 22:12:59 +0200
> From: Paul Eggert <eggert <at> cs.ucla.edu>
> Date: Tue, 13 Nov 2018 10:26:43 -0800
> Cc: 33255-done <at> debbugs.gnu.org, immerrr again <immerrr <at> gmail.com>,
> 	Noam Postavsky <npostavs <at> gmail.com>
> 
> > I think a non-absolute HOME is a user error.
> > Eg cd $HOME may then not be idempotent.
> That's true. However, POSIX says that sh treats ~/foo like $HOME/foo 
> even when HOME is not absolute, and it's better if Emacs is consistent 
> with POSIX as much as possible within the Emacs constraint that 
> expand-file-name must expand to an absolute file name. So I implemented 
> something along the line of Noam's suggestion by installing the attached 
> patch into master; this should fix the bug originally reported.
> 
> Unlike Noam's suggestion, this patch causes Emacs to look at the current 
> value of HOME, not the value HOME had when Emacs started up, as that 
> corresponds more closely to POSIX sh.

Thanks.  I think this needs to be called out in NEWS as an
incompatible change, and probably also documented in the manuals.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#33255; Package emacs. (Wed, 14 Nov 2018 18:12:02 GMT) Full text and rfc822 format available.

Message #22 received at 33255 <at> debbugs.gnu.org (full text, mbox):

From: Glenn Morris <rgm <at> gnu.org>
To: Paul Eggert <eggert <at> cs.ucla.edu>
Cc: 33255 <at> debbugs.gnu.org, immerrr again <immerrr <at> gmail.com>,
 Noam Postavsky <npostavs <at> gmail.com>
Subject: Re: 27.0.50;
 expand-file-name: default directory expanded twice if relative
Date: Wed, 14 Nov 2018 13:10:44 -0500
Paul Eggert wrote:

> However, POSIX says that sh treats ~/foo like $HOME/foo even when HOME
> is not absolute [...]

Can you point me to the citation for that please (I'm not doubting you,
just interested to read the wording, which I could not find).

I'm a bit disappointed to see that a relative HOME is now documented
in the Emacs manuals, since IMO it lends legitimacy to a questionable
usage. I don't see it mentioned in eg the bash manual.
I also don't see why it is in NEWS since it is described as
a bug fix, and those aren't normally mentioned.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#33255; Package emacs. (Wed, 14 Nov 2018 18:19:01 GMT) Full text and rfc822 format available.

Message #25 received at 33255 <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Glenn Morris <rgm <at> gnu.org>
Cc: 33255 <at> debbugs.gnu.org, immerrr again <immerrr <at> gmail.com>,
 Noam Postavsky <npostavs <at> gmail.com>
Subject: Re: 27.0.50; expand-file-name: default directory expanded twice if
 relative
Date: Wed, 14 Nov 2018 10:17:59 -0800
On 11/14/18 10:10 AM, Glenn Morris wrote:
> Can you point me to the citation for that please

http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_01

> I'm a bit disappointed to see that a relative HOME is now documented
> in the Emacs manuals, since IMO it lends legitimacy to a questionable
> usage. I don't see it mentioned in eg the bash manual.
> I also don't see why it is in NEWS since it is described as
> a bug fix, and those aren't normally mentioned.

My initial reaction was the same as yours, which is why my original fix 
didn't document the change in the manual or in NEWS. Eli felt otherwise, 
though.





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#33255; Package emacs. (Wed, 14 Nov 2018 19:53:02 GMT) Full text and rfc822 format available.

Message #28 received at 33255 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Paul Eggert <eggert <at> cs.ucla.edu>
Cc: rgm <at> gnu.org, immerrr <at> gmail.com, npostavs <at> gmail.com, 33255 <at> debbugs.gnu.org
Subject: Re: bug#33255: 27.0.50;
 expand-file-name: default directory expanded twice if relative
Date: Wed, 14 Nov 2018 21:52:23 +0200
> From: Paul Eggert <eggert <at> cs.ucla.edu>
> Date: Wed, 14 Nov 2018 10:17:59 -0800
> Cc: 33255 <at> debbugs.gnu.org, immerrr again <immerrr <at> gmail.com>,
> 	Noam Postavsky <npostavs <at> gmail.com>
> 
> > I'm a bit disappointed to see that a relative HOME is now documented
> > in the Emacs manuals, since IMO it lends legitimacy to a questionable
> > usage. I don't see it mentioned in eg the bash manual.
> > I also don't see why it is in NEWS since it is described as
> > a bug fix, and those aren't normally mentioned.
> 
> My initial reaction was the same as yours, which is why my original fix 
> didn't document the change in the manual or in NEWS. Eli felt otherwise, 
> though.

I agree that we should discourage relative $HOME, so I added text to
the documentation to that effect.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#33255; Package emacs. (Tue, 20 Nov 2018 19:09:02 GMT) Full text and rfc822 format available.

Message #31 received at 33255 <at> debbugs.gnu.org (full text, mbox):

From: Glenn Morris <rgm <at> gnu.org>
To: Paul Eggert <eggert <at> cs.ucla.edu>
Cc: 33255 <at> debbugs.gnu.org, immerrr again <immerrr <at> gmail.com>,
 Noam Postavsky <npostavs <at> gmail.com>
Subject: Re: 27.0.50;
 expand-file-name: default directory expanded twice if relative
Date: Tue, 20 Nov 2018 14:08:08 -0500
Paul Eggert wrote:

> On 11/14/18 10:10 AM, Glenn Morris wrote:
>> Can you point me to the citation for that please
>
> http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_01

I had looked at that page before. Looking again, I still don't see
anything as clear-cut as "POSIX says that sh treats ~/foo like $HOME/foo
even when HOME is not absolute".

There are no matches for "relative" on that page.
There are three for "absolute". One is for ENV, and says that the
results are unspecified if it is not absolute. The other two are for
PWD, and say that it must be absolute.

What am I missing?
Just that the section on ~ expansion says nothing one way or the other?
I was really looking for a reference about HOME.





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#33255; Package emacs. (Tue, 20 Nov 2018 19:12:01 GMT) Full text and rfc822 format available.

Message #34 received at 33255 <at> debbugs.gnu.org (full text, mbox):

From: Glenn Morris <rgm <at> gnu.org>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 33255 <at> debbugs.gnu.org, Paul Eggert <eggert <at> cs.ucla.edu>, immerrr <at> gmail.com,
 npostavs <at> gmail.com
Subject: Re: bug#33255: 27.0.50;
 expand-file-name: default directory expanded twice if relative
Date: Tue, 20 Nov 2018 14:11:00 -0500
Eli Zaretskii wrote:

> I agree that we should discourage relative $HOME, so I added text to
> the documentation to that effect.

I really think it would be better not to mention it at all.
I have never heard of it in many years of using Unix (I know this is an
awful kind of statement), and see no need for it. Again, the GNU Bash
manual says nothing about this.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#33255; Package emacs. (Tue, 20 Nov 2018 19:27:02 GMT) Full text and rfc822 format available.

Message #37 received at 33255 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Glenn Morris <rgm <at> gnu.org>
Cc: 33255 <at> debbugs.gnu.org, eggert <at> cs.ucla.edu, immerrr <at> gmail.com,
 npostavs <at> gmail.com
Subject: Re: bug#33255: 27.0.50;
 expand-file-name: default directory expanded twice if relative
Date: Tue, 20 Nov 2018 21:26:32 +0200
> From: Glenn Morris <rgm <at> gnu.org>
> Cc: Paul Eggert <eggert <at> cs.ucla.edu>,  33255 <at> debbugs.gnu.org,  immerrr <at> gmail.com,  npostavs <at> gmail.com
> Date: Tue, 20 Nov 2018 14:11:00 -0500
> 
> Eli Zaretskii wrote:
> 
> > I agree that we should discourage relative $HOME, so I added text to
> > the documentation to that effect.
> 
> I really think it would be better not to mention it at all.

Sorry, I disagree.  We should not hide from the users what Emacs does
in such corner cases.  Hiding won't work anyway, because someone
determined enough will find out by reading the code.  We just punish
those who aren't determined enough.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#33255; Package emacs. (Tue, 20 Nov 2018 20:45:02 GMT) Full text and rfc822 format available.

Message #40 received at 33255 <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Glenn Morris <rgm <at> gnu.org>
Cc: 33255 <at> debbugs.gnu.org, immerrr again <immerrr <at> gmail.com>,
 Noam Postavsky <npostavs <at> gmail.com>
Subject: Re: 27.0.50; expand-file-name: default directory expanded twice if
 relative
Date: Tue, 20 Nov 2018 12:44:25 -0800
On 11/20/18 11:08 AM, Glenn Morris wrote:
>> http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_01
> I had looked at that page before. Looking again, I still don't see
> anything as clear-cut as "POSIX says that sh treats ~/foo like $HOME/foo
> even when HOME is not absolute".

It needs to be read in context. Section 2.6.1 is about tilde expansion 
in the shell, e.g., how to treat commands like this:

cd ~eggert/xxx
cd ~/yyy

2.6.1 says "If the login name is null (that is, the tilde-prefix 
contains only the tilde), the tilde-prefix is replaced by the value of 
the variable /HOME."/ This is talking about the second "echo" example 
which uses a null login name, and it means that the second example is 
treated like this:

cd "$HOME"/yyy/
/

(The quotes are because of the last sentence in that section of the 
spec.) This occurs regardless of whether $HOME starts with /"/".//
/





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#33255; Package emacs. (Thu, 22 Nov 2018 18:26:01 GMT) Full text and rfc822 format available.

Message #43 received at 33255 <at> debbugs.gnu.org (full text, mbox):

From: Glenn Morris <rgm <at> gnu.org>
To: Paul Eggert <eggert <at> cs.ucla.edu>
Cc: 33255 <at> debbugs.gnu.org, immerrr again <immerrr <at> gmail.com>,
 Noam Postavsky <npostavs <at> gmail.com>
Subject: Re: 27.0.50;
 expand-file-name: default directory expanded twice if relative
Date: Thu, 22 Nov 2018 13:25:20 -0500
Paul Eggert wrote:

> It needs to be read in context. Section 2.6.1 is about tilde expansion
> in the shell, e.g., how to treat commands like this:
>
> cd ~eggert/xxx
> cd ~/yyy
>
> 2.6.1 says "If the login name is null (that is, the tilde-prefix
> contains only the tilde), the tilde-prefix is replaced by the value of
> the variable /HOME."/ This is talking about the second "echo" example
> which uses a null login name, and it means that the second example is
> treated like this:
>
> cd "$HOME"/yyy/

This seems to be telling me what tilde expansion is.

I am at this point looking for any documentation (not even from POSIX,
any shell or frankly any Unix utility will do) that says "HOME need not
be absolute, if not, here's how that is handled". So far all I see from
POSIX is that it doesn't say anything about whether HOME is absolute or
not.





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#33255; Package emacs. (Fri, 23 Nov 2018 20:23:02 GMT) Full text and rfc822 format available.

Message #46 received at 33255 <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Glenn Morris <rgm <at> gnu.org>
Cc: 33255 <at> debbugs.gnu.org, immerrr again <immerrr <at> gmail.com>,
 Noam Postavsky <npostavs <at> gmail.com>
Subject: Re: 27.0.50; expand-file-name: default directory expanded twice if
 relative
Date: Fri, 23 Nov 2018 12:22:19 -0800
Glenn Morris wrote:
> So far all I see from POSIX is that it doesn't say anything about whether HOME is absolute or not.

By not saying anything POSIX gives permission to the application to set HOME to 
a relative name. When POSIX intends the requirement that an environment 
variable's value must be absolute (e.g., PWD), it says so. When it doesn't 
intend such a requirement (e.g., HOME, PATH, SHELL, TMPDIR) it says nothing.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#33255; Package emacs. (Tue, 27 Nov 2018 05:43:02 GMT) Full text and rfc822 format available.

Message #49 received at 33255 <at> debbugs.gnu.org (full text, mbox):

From: Glenn Morris <rgm <at> gnu.org>
To: Paul Eggert <eggert <at> cs.ucla.edu>
Cc: 33255 <at> debbugs.gnu.org, immerrr again <immerrr <at> gmail.com>,
 Noam Postavsky <npostavs <at> gmail.com>
Subject: Re: 27.0.50;
 expand-file-name: default directory expanded twice if relative
Date: Tue, 27 Nov 2018 00:42:16 -0500
Paul Eggert wrote:

> By not saying anything POSIX gives permission to the application to
> set HOME to a relative name. When POSIX intends the requirement that
> an environment variable's value must be absolute (e.g., PWD), it says
> so. When it doesn't intend such a requirement (e.g., HOME, PATH,
> SHELL, TMPDIR) it says nothing.

So the justification for implementing this is indeed "it's not
explicitly forbidden".

Here's an example of how this can be confusing:

cd /tmp
mkdir foo
echo hi > foo/bar
HOME=foo emacs
C-x C-f ~/bar   ; works
M-: (shell-command "ls ~/bar")  ; fails

So, Emacs and external processes it spawns interpret ~ differently;
ie external processes are likely to fail in odd ways. All this would be
avoided if the user had just said HOME=$PWD/foo to start with.

>> I am at this point looking for any documentation (not even from POSIX,
>> any shell or frankly any Unix utility will do) that says "HOME need
>> not be absolute, if not, here's how that is handled".

AFAICS Emacs is the only thing documenting this scenario.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#33255; Package emacs. (Tue, 27 Nov 2018 18:12:01 GMT) Full text and rfc822 format available.

Message #52 received at 33255 <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Glenn Morris <rgm <at> gnu.org>
Cc: 33255 <at> debbugs.gnu.org, immerrr again <immerrr <at> gmail.com>,
 Noam Postavsky <npostavs <at> gmail.com>
Subject: Re: 27.0.50; expand-file-name: default directory expanded twice if
 relative
Date: Tue, 27 Nov 2018 10:11:34 -0800
On 11/26/18 9:42 PM, Glenn Morris wrote:
> Here's an example of how this can be confusing:
>
> cd /tmp
> mkdir foo
> echo hi > foo/bar
> HOME=foo emacs
> C-x C-f ~/bar   ; works
> M-: (shell-command "ls ~/bar")  ; fails

Yes, and there's a similar confusion in ordinary POSIX shells:

$ cd /tmp
$ mkdir foo
$ echo hi > foo/bar
$ HOME=foo sh
$ cat ~/bar
hi
$ cd
$ cat ~/bar
cat: foo/bar: No such file or directory

The moral of this story in POSIX is "Don't set HOME to a relative file 
name, as it's trouble for any application that chdirs." In your example 
Emacs chdirs; in mine, sh chdirs.

The question is whether Emacs should attempt to insulate users from this 
trouble, presumably by replacing HOME with an absolute directory name 
when HOME's value is relative (or is absent or empty, for that matter). 
The POSIX shell doesn't do that, which is an argument for Emacs not 
doing it either.





bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Wed, 26 Dec 2018 12:24:05 GMT) Full text and rfc822 format available.

This bug report was last modified 6 years and 261 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.