Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 6a816e3ca05a7b9864733dc16ea69d33afc810df
Ticket: 5bfe3de008e6f7b5863619a4f9c801d040ff5ab8
^Z appended to sourced VFS files
User & Date: andy on 2017-08-09 21:45:13
Changes

  1. icomment:
    Yes aku, you have it right, this is a confluence of issues, a problem that doesn't exist in any one subsystem but rather in the their integration.
    
    The mode originates with the user script, either as an argument to [open] or implied "r" for [source].  It is sent to the VFS, which then sends it to the channel code.
    
    We've gotten so flexible that several stages of this process are allowed to reflect back into the user script.  Both the VFS and the channel can be customized.  While I'm thrilled Tcl has grown in this direction, there's a lot that can go wrong.
    
    We are trusting the user-supplied VFS to correctly relay the mode from the VFS subsystem to the I/O subsystem, which are two different realms.  The boundary is quite blurred since user VFSes often don't call [chan create] directly but instead use a wrapper supplied by the custom refchan package, yet despite this code being ostensibly part of the refchan, it is effectively part of the VFS.  Thus the VFS has responsibility without authority, which is always a bad combination.
    
    When I say "two different realms" I have in mind the totally different ways VFS and refchan represent modes.  VFS has numeric (typically octal) permissions used in case a new file is created, but that has no bearing here except to sew confusion.  It also has a mode string which is either "", "w", "a", "w+", or "a+".  Contrast that with refchan which has a mode of "read", "write", or "read write".  The custom VFS is responsible for translating the former to the latter, and it's so much easier to just say "read write" always.  Wouldn't it make more sense to unify the representation of modes, to replace mode strings with refchan-style lists?
    
    VFS modes say not only which operations are permitted, but also whether the initial file pointer should be at the end or the beginning.  This could be represented by having (or not having) "append" be in the mode list.  Then make refchan ignore "append" so the mode list can be passed along directly, eliminating any need for translation.  The goal is for the right thing to also be the easy thing so users are less likely to take shortcuts or make mistakes.
    
    Further complicating the issue, the [open] command has two more similar but incompatible ways of describing modes.  It has mode strings, but they're not the same as VFS mode strings.  In particular, [open] supports "r" and "r+" which VFS encodes as "" and "a+".  It also supports a "b" qualifier.  In addition to mode strings, [open] allows lists of RDONLY, WRONLY, or RDWR plus any number of extra flags such as APPEND and BINARY.
    
    One more issue to top it all off.  The VFS man page, which I found at http://jsish.org/man/mann/vfs.html, says the read-only open mode is "r" whereas in reality it's empty string.
    
    So yeah, we can improve Tcllib to respect modes, but I think that just like my [source] change, that would also be missing the underlying issue, which is that it's much harder than it should be to correctly transmit the mode from the VFS subsystem to the I/O channel subsystem.  Until that's addressed, this bug will continue to crop up in user programs.
    
  2. login: "andy"
  3. mimetype: "text/plain"
  4. username: "Andy Goth"