Artifacts Associated With Ticket eeab905428
Ticket change [193d4f154c] (rid 217264) by juliannoble2 on 2023-08-20 13:24:59:
- assignee initialized to: "nobody"
- closer initialized to: "nobody"
- cmimetype initialized to: "text/x-fossil-plain"
- comment initialized to:
The file glob command semantics of returning a single list of results doesn't allow for gathering other information that should be available in a single call to the filesystem. For example - a search/audit program that walks the filesystem may reasonably need to gather both subdirectories and files for each node. Whilst glob lets you search for files and dirs at once - they are not distinguished in the results. It is also inefficient in that, at least on some filesystems - other information such as file size (and attributes) is available in the same API call that gathers the directory contents. This is particularly a concern on windows - where the interaction with the slow 'file glob'/'file attributes' etc calls and multiple required calls to glob because of current semantics make the slow-downs massive. (see ticket: https://core.tcl-lang.org/tcl/tktview/411f52ed87) The request is for an enhancement to file glob - something like -dict ?desired keys|all? that will return a dict containing at least the keys files & dirs & links and ideally a filesizes key where the value is the size of each file in the same order as returned by the list of names in files. That way the caller could process using: foreach fname [dict get $result files] fsize [dict get $result filesizes] ... Other file or directory attributes could have their own key for ordered results. If a particular platform can't gather the information - an empty list could be returned for that attribute list, requiring the caller to make repeated calls to gather it if required. The semantic shortcomings of glob become apparent when attempting to implement a pure tcl equivalent of the unix du command. Initial attempts gave results around 20x worse than execing out to du - but by using twapi on windows to reduce the number of required glob calls and file size calls - the performance acheivable was much better than an external tool for small and medium size trees, and even competitive or better on some larger systems. I know of no such optimisation on unix-like platforms - so presumably pure Tcl script remains uncompetitive with external tools and other languages for a class of filesystem-walking operations - when it doesn't need to be.
- foundin initialized to: "Any"
- is_private initialized to: "0"
- login: "juliannoble2"
- priority initialized to: "5 Medium"
- private_contact initialized to: "957fdfcd8744611e3fe1f4896c7538b1d9bf47b2"
- resolution initialized to: "None"
- severity initialized to: "Important"
- status initialized to: "Open"
- submitter initialized to: "juliannoble2"
- subsystem initialized to: "37. File System"
- title initialized to:
file glob semantics - support efficient retrieval - reduce round trips
- type initialized to: "RFE"
Ticket change [e0462f7472] (rid 217269) by juliannoble2 on 2023-08-20 13:44:42:
- icomment:
When I say above 'same API call' - I don't necessarily mean that it's a single API call as I'm generally unaware of those details as they pertain to the various platforms. When using Twapi - it was a call to find_file_open which returned an iterator, which then required a loop of calls to find_file_next. This was faster than repeatedly calling standard tcl 'file' ensemble commands. My point is that this seems to demonstrate that a single scripting call could gather the information much faster if the semantics were different. Whether this translates to reduced round trips to the filesystem itself is unclear to me.. but if so, or even if it could be done in one Tcl call, it would certainly be desirable both for local and network storage.
- login: "juliannoble2"
- mimetype: "text/plain"
- icomment:
Ticket change [96b576e23d] (rid 217270) by juliannoble2 on 2023-08-20 16:32:25:
- icomment:
Further related. On both unix and windows if you have a subfolder with restricted permissions then a glob using join ( or */* etc) produces inconsistent results % glob -dir . -join * test.txt ./plainfolder/test.txt ./link_to_plainfolder/test.txt ./stuff/test.txt % glob -dir . -join * *.txt couldn't read directory "/usr/local/etc/ansible/foldertest/restricted/": permission denied % glob -dir . -join * * couldn't read directory "/usr/local/etc/ansible/foldertest/restricted/": permission denied Arguably the the restricted folder should either cause this glob to emit an error in all cases or none. Perhaps this decision was a design decision regarding the integrity of what is returned - ie better to error out than return incomplete results. If there is any merit in my above suggestion of a return dict for glob - then it may make sense to ignore inaccessible intermediate folders like this and return only what can be reached - and accumulate errors in a dict returnable key such as -errorpaths
- login: "juliannoble2"
- mimetype: "text/plain"
- icomment: