Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 51847a2a1af0f27f5c05b674a37d495fb9941342f455bf57f112a42ef751c5a9
Ticket: 4f322b9d2112772a4a9599611def6e651f8e5198
Impossibility to create an unique path in Tcl (e. g. using file mkdir)
User & Date: sebres on 2018-07-02 12:12:33
Changes

  1. assignee changed to: "nobody"
  2. closer changed to: "nobody"
  3. cmimetype changed to: "text/x-fossil-wiki"
  4. comment changed to:
    If working multi-threaded (or multi-processed in cluster-system on share) with some global directory to create some system-wide unique sub-path using some pseudo-unique name generation algorithm (also UUID), to avoid retrieving of the same folder for two workers, one can do the things like this:
    <code><pre style="padding-left:10pt">
    proc get_unique_dir {} {
      while 1 {
        set p [file join $GLOB_PATH [some_uuid_algo]]
        if {![file exists $p]} {
          file mkdir $p
          break
        }
      }
      return $p
    }
    </pre></code>
    
    But it's affected by the race condition (firstly not exists for both workers, then one creates sub-path, another returns with no error in `file mkdir` on same existing path), if some_uuid_algo cannot guarantee a system-wide unique path.
    
    So the creation of a safe construct for that is impossible in Tcl currently.
    
    <b>Suggestion:</b>
    
    Currently `file mkdir` returns no result at all. <br/>
    If `TclFileMakeDirsCmd` will be extended with return value as counter (of created <b>tail</b>-directories), one may use it to avoid race condition in above-mentioned script, like here:
    <code><pre style="padding-left:10pt">
    proc get_unique_dir {} {
      while 1 {
        set p [file join $GLOB_PATH [some_uuid_algo]]
        if {[file mkdir $p]} {
          break
        }
      }
      return $p
    }
    </pre></code>
    
    This is race condition safe.
    The only one backwards-incompatibility in this case would be usage like this:
    <code><pre style="padding-left:10pt">
    set some_var "when [file mkdir $some_path]was used in substitution"
    </pre></code>
    But I believe the way like this is very rarely (or almost never) used.
    
  5. foundin changed to: ">= 8.5"
  6. is_private changed to: "0"
  7. login: "sebres"
  8. priority changed to: "5 Medium"
  9. resolution changed to: "None"
  10. severity changed to: "Minor"
  11. status changed to: "Open"
  12. submitter changed to: "sebres"
  13. subsystem changed to: "16. Commands A-H"
  14. title changed to:
    Impossibility to create an unique path in Tcl (e. g. using file mkdir)
    
  15. type changed to: "RFE"