cmdr
Check-in [e7f547d6aa]
Not logged in
Bounty program for improvements to Tcl and certain Tcl packages.
Tcl 2019 Conference, Houston/TX, US, Nov 4-8
Send your abstracts to [email protected]
or submit via the online form by Sep 9.

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:cmdr::validate::common - Consolidated multiple copies of "OkDir" in cmdr::validate into a single shared helper command "ok-directory".
Timelines: family | ancestors | descendants | both | more-vtypes
Files: files | file ages | folders
SHA1: e7f547d6aa1bf5d405da129a201673e9c83b75bf
User & Date: andreask 2014-03-13 18:34:01
Context
2014-03-13
18:36
cmdr::validate - Replaced all uses of "OkDir" with the shared "ok-directory". Changed the "rw*" types to allow missing file/dir/path like the "w*" types.. Fixed the fail messages for "wfile" and "wchan". check-in: 62fbd92a1b user: andreask tags: more-vtypes
18:34
cmdr::validate::common - Consolidated multiple copies of "OkDir" in cmdr::validate into a single shared helper command "ok-directory". check-in: e7f547d6aa user: andreask tags: more-vtypes
2014-02-19
19:39
Modified the checks for wfile/wchan to allow non-existing files which can be created (per permissions). check-in: 9ab661bcd1 user: andreask tags: more-vtypes
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to vcommon.tcl.

    33     33   
    34     34   namespace eval ::cmdr::validate {
    35     35       namespace export common
    36     36       namespace ensemble create
    37     37   }
    38     38   
    39     39   namespace eval ::cmdr::validate::common {
    40         -    namespace export fail complete-enum complete-glob
           40  +    namespace export fail complete-enum complete-glob ok-directory
    41     41       namespace ensemble create
    42     42   }
    43     43   
    44     44   # # ## ### ##### ######## ############# #####################
    45     45   
    46     46   debug define cmdr/validate/common
    47     47   debug level  cmdr/validate/common
................................................................................
   102    102   	if {![{*}$filter $path]} continue
   103    103   	lappend candidates $path
   104    104       }
   105    105   
   106    106       debug.cmdr/validate/common {= [join $candidates "\n= "]} 10
   107    107       return $candidates
   108    108   }
          109  +
          110  +proc ::cmdr::validate::common::ok-directory {path} {
          111  +    if {![file exists $path]} {
          112  +
          113  +	# The directory is allowed to not exist if its parent
          114  +	# directory exists and is writable.
          115  +	# Note: Prevent us from walking up the chain if the directory
          116  +	# has no parent.
          117  +	# Note 2: Switch to absolute notation if path is the relative
          118  +	# name of the CWD (i.e. ".").
          119  +	if {$path eq "."} {
          120  +	    set path [pwd]
          121  +	}
          122  +	set up [file dirname $path]
          123  +	if {$up eq $path} {
          124  +	    # Reached root (/, x:, x:/), found it missing, stop & fail.
          125  +	    return 0
          126  +	}
          127  +	return [ok-directory $up]
          128  +    }
          129  +    if {![file isdirectory $path]} {return 0}
          130  +    if {![file writable    $path]} {return 0}
          131  +    return 1
          132  +}
   109    133   
   110    134   # # ## ### ##### ######## ############# #####################
   111    135   ## Ready
   112         -package provide cmdr::validate::common 1.1
          136  +package provide cmdr::validate::common 1.2
   113    137   return