Ticket UUID: | 4f322b9d2112772a4a9599611def6e651f8e5198 | |||
Title: | Impossibility to create an unique path in Tcl (e. g. using file mkdir) | |||
Type: | RFE | Version: | >= 8.5 | |
Submitter: | sebres | Created on: | 2018-07-02 12:12:33 | |
Subsystem: | 16. Commands A-H | Assigned To: | nobody | |
Priority: | 5 Medium | Severity: | Minor | |
Status: | Pending | Last Modified: | 2018-10-10 22:41:54 | |
Resolution: | Fixed | Closed By: | nobody | |
Closed on: | ||||
Description: |
(text/x-fossil-wiki)
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. | |||
User Comments: |
sebres added on 2018-10-10 22:41:54:
(text/x-fossil-wiki)
So [270f78ca95b642fb] is definitely closed, well it is time to "close" another race-condition (this RFE fixed).<br/> Someone with an idea to bring this thing further?<br/> I spoke to several people: no one has used <code>[file mkdir]</code> to get/check empty return value / or somehow expected empty values in string like <code>"...[file mkdir]..."</code> or similar imaginable substitutions.<br/> Any suggetions, proposals, etc? aspect added on 2018-07-12 09:43:10: I approve of this change. Can we afford to break code that relies on the empty result from [file mkdir]? See also https://core.tcl.tk/tips/doc/trunk/tip/431.md and the ensuing wiki discussion at https://wiki.tcl.tk/40609 https://core.tcl.tk/tcl/info/270f78ca95b642fb is also relevant. sebres added on 2018-07-02 15:05:03: (text/x-fossil-wiki) Implemented in branch [./vdiff?from=core-8-5-branch&to=rfe-4f322b9d21|rfe-4f322b9d21] for >= 8.5th. Although I think, it could be accepted as it's, adding a short changelog entry with small incompatibility note like: command `file mkdir` returns integer now vs. nothing previously... But TCT should decide about it. So pending as implemented. |