Tcl Library Source Code

Changes On Branch bug-8b317b4a63-fileutil
Login

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

Changes In Branch bug-8b317b4a63-fileutil Excluding Merge-Ins

This is equivalent to a diff from 7a7e5b34ac to 4afba263b2

2013-07-15
17:20
Merged fix for bug [8b317b4a63], made it official. check-in: 1298908cdd user: andreask tags: trunk
2013-07-11
17:25
Ticket [8b317b4a63]: Added code to the 8.4+ implementations of GLOBF and GLOBD to guard ourselves against VFS packages mishandling the -types option of [glob]. vfs::zip is an example. This mishandling causes glob to return the same data for the two calls with "-types x" and "-types {hidden x}", generating lists with duplicate entries. We now generally de-duplicate the result ourselves. Bumped the package version to 1.14.6. Thanks to <[email protected]> for the investigation identifying this problem. Closed-Leaf check-in: 4afba263b2 user: andreask tags: bug-8b317b4a63-fileutil
2013-06-19
18:17
New command 'many-json2dict' to parse strings containing more than one JSON entity. The existing json2dict command will return only the first. Updated documentation. Extended testsuite. Package version bumped to 1.2 check-in: 7a7e5b34ac user: andreask tags: trunk
2013-06-05
20:41
Regenerated documentation for shorter provenance comment. check-in: 1dc7f4df4f user: andreask tags: trunk

Changes to modules/fileutil/ChangeLog.














1
2
3
4
5
6
7













2013-02-14  Andreas Kupries  <[email protected]>

	* decode.tcl: Bumped fileutil::decode to 0.2 to distinguish
	* pkgIndex.tcl: properly from the 0.1.xxx version which existed in
	  AS/perforce before it moved to tcllib/fossil. That should have
	  been done as part of the move, and was forgotten.

>
>
>
>
>
>
>
>
>
>
>
>
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
2013-07-11  Andreas Kupries  <[email protected]>

	* fileutil.man: Ticket [8b317b4a63]: Added code to the 8.4+
	* fileutil.tcl: implementations of GLOBF and GLOBD to guard
	* fileutil.test: ourselves against VFS packages mishandling the
	* pkgIndex.tcl: -types option of [glob]. vfs::zip is an example.
	  This mishandling causes glob to return the same data for the two
	  calls with "-types x" and "-types {hidden x}", generating lists
	  with duplicate entries. We now generally de-duplicate the result
	  ourselves. Bumped the package version to 1.14.6. Thanks to
	  <[email protected]> for the investigation identifying
	  this problem.

2013-02-14  Andreas Kupries  <[email protected]>

	* decode.tcl: Bumped fileutil::decode to 0.2 to distinguish
	* pkgIndex.tcl: properly from the 0.1.xxx version which existed in
	  AS/perforce before it moved to tcllib/fossil. That should have
	  been done as part of the move, and was forgotten.

Changes to modules/fileutil/fileutil.man.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

[comment {-*- tcl -*- doctools manpage}]
[manpage_begin fileutil n 1.14.5]
[keywords cat]
[keywords {file utilities}]
[keywords grep]
[keywords {temp file}]
[keywords test]
[keywords touch]
[keywords type]
[moddesc   {file utilities}]
[titledesc {Procedures implementing some file utilities}]
[category  {Programming tools}]
[require Tcl 8]
[require fileutil [opt 1.14.5]]
[description]
[para]

This package provides implementations of standard unix utilities.

[list_begin definitions]

>

|











|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
[vset PACKAGE_VERSION 1.14.6]
[comment {-*- tcl -*- doctools manpage}]
[manpage_begin fileutil n [vset PACKAGE_VERSION]]
[keywords cat]
[keywords {file utilities}]
[keywords grep]
[keywords {temp file}]
[keywords test]
[keywords touch]
[keywords type]
[moddesc   {file utilities}]
[titledesc {Procedures implementing some file utilities}]
[category  {Programming tools}]
[require Tcl 8]
[require fileutil [opt [vset PACKAGE_VERSION]]]
[description]
[para]

This package provides implementations of standard unix utilities.

[list_begin definitions]

Changes to modules/fileutil/fileutil.tcl.

9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
# 
# RCS: @(#) $Id: fileutil.tcl,v 1.78 2010/06/17 04:46:19 andreas_kupries Exp $

package require Tcl 8.2
package require cmdline
package provide fileutil 1.14.5

namespace eval ::fileutil {
    namespace export \
	    grep find findByPattern cat touch foreachLine \
	    jail stripPwd stripN stripPath tempdir tempfile \
	    install fileType writeFile appendToFile \
	    insertIntoFile removeFromFile replaceInFile \







|







9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
# 
# RCS: @(#) $Id: fileutil.tcl,v 1.78 2010/06/17 04:46:19 andreas_kupries Exp $

package require Tcl 8.2
package require cmdline
package provide fileutil 1.14.6

namespace eval ::fileutil {
    namespace export \
	    grep find findByPattern cat touch foreachLine \
	    jail stripPwd stripN stripPath tempdir tempfile \
	    install fileType writeFile appendToFile \
	    insertIntoFile removeFromFile replaceInFile \
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
	}
	if {([file type $current] eq "link") &&
	    !([file exists   [file readlink $current]] &&
	      [file readable [file readlink $current]])} {
	    return {}
	}

	set res [concat \
		     [glob -nocomplain -directory $current -types f          -- *] \
		     [glob -nocomplain -directory $current -types {hidden f} -- *]]

	# Look for broken links (They are reported as neither file nor directory).
	foreach l [concat \
		       [glob -nocomplain -directory $current -types l          -- *] \
		       [glob -nocomplain -directory $current -types {hidden l} -- *] ] {
	    if {[file isfile      $l]} continue
	    if {[file isdirectory $l]} continue
	    lappend res $l
	}
	return $res
    }

    proc ::fileutil::GLOBD {current} {
	if {![file readable $current]} {
	    return {}
	}
	if {([file type $current] eq "link") &&
	    !([file exists   [file readlink $current]] &&
	      [file readable [file readlink $current]])} {
	    return {}
	}

	concat \
	    [glob -nocomplain -directory $current -types d          -- *] \
	    [glob -nocomplain -directory $current -types {hidden d} -- *]
    }

} elseif {[package vsatisfies [package present Tcl] 8.4]} {
    # Tcl 8.4+.
    # (Ad 1) We have -directory, and -types,
    # (Ad 2) Links are returned for -types f/d if they refer to files/dirs.
    # (Ad 3) No bug to code around

    proc ::fileutil::ACCESS {args} {}

    proc ::fileutil::GLOBF {current} {
	set res [concat \
		     [glob -nocomplain -directory $current -types f          -- *] \
		     [glob -nocomplain -directory $current -types {hidden f} -- *]]

	# Look for broken links (They are reported as neither file nor directory).
	foreach l [concat \
		       [glob -nocomplain -directory $current -types l          -- *] \
		       [glob -nocomplain -directory $current -types {hidden l} -- *] ] {
	    if {[file isfile      $l]} continue
	    if {[file isdirectory $l]} continue
	    lappend res $l
	}
	return $res
    }

    proc ::fileutil::GLOBD {current} {
	concat \
	    [glob -nocomplain -directory $current -types d          -- *] \
	    [glob -nocomplain -directory $current -types {hidden d} -- *]
    }

} elseif {[package vsatisfies [package present Tcl] 8.3]} {
    # 8.3.
    # (Ad 1) We have -directory, and -types,
    # (Ad 2) Links are NOT returned for -types f/d, collect separately.
    #        No symbolic file links on Windows.







|

|


|

|




|












|

|











|
|
|


|

|




|



|

|







225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
	}
	if {([file type $current] eq "link") &&
	    !([file exists   [file readlink $current]] &&
	      [file readable [file readlink $current]])} {
	    return {}
	}

	set res [lsort -unique [concat \
		     [glob -nocomplain -directory $current -types f          -- *] \
		     [glob -nocomplain -directory $current -types {hidden f} -- *]]]

	# Look for broken links (They are reported as neither file nor directory).
	foreach l [lsort -unique [concat \
		       [glob -nocomplain -directory $current -types l          -- *] \
		       [glob -nocomplain -directory $current -types {hidden l} -- *]]] {
	    if {[file isfile      $l]} continue
	    if {[file isdirectory $l]} continue
	    lappend res $l
	}
	return [lsort -unique $res]
    }

    proc ::fileutil::GLOBD {current} {
	if {![file readable $current]} {
	    return {}
	}
	if {([file type $current] eq "link") &&
	    !([file exists   [file readlink $current]] &&
	      [file readable [file readlink $current]])} {
	    return {}
	}

	lsort -unique [concat \
	    [glob -nocomplain -directory $current -types d          -- *] \
	    [glob -nocomplain -directory $current -types {hidden d} -- *]]
    }

} elseif {[package vsatisfies [package present Tcl] 8.4]} {
    # Tcl 8.4+.
    # (Ad 1) We have -directory, and -types,
    # (Ad 2) Links are returned for -types f/d if they refer to files/dirs.
    # (Ad 3) No bug to code around

    proc ::fileutil::ACCESS {args} {}

    proc ::fileutil::GLOBF {current} {
	set res [lsort -unique [concat \
		    [glob -nocomplain -directory $current -types f          -- *] \
		    [glob -nocomplain -directory $current -types {hidden f} -- *]]]

	# Look for broken links (They are reported as neither file nor directory).
	foreach l [lsort -unique [concat \
		       [glob -nocomplain -directory $current -types l          -- *] \
		       [glob -nocomplain -directory $current -types {hidden l} -- *]]] {
	    if {[file isfile      $l]} continue
	    if {[file isdirectory $l]} continue
	    lappend res $l
	}
	return [lsort -unique $res]
    }

    proc ::fileutil::GLOBD {current} {
	lsort -unique [concat \
	    [glob -nocomplain -directory $current -types d          -- *] \
	    [glob -nocomplain -directory $current -types {hidden d} -- *]]
    }

} elseif {[package vsatisfies [package present Tcl] 8.3]} {
    # 8.3.
    # (Ad 1) We have -directory, and -types,
    # (Ad 2) Links are NOT returned for -types f/d, collect separately.
    #        No symbolic file links on Windows.

Changes to modules/fileutil/fileutil.test.

1
2
3
4
5
6
7
8
9
10
11
12




13
14
15
16
17
18
19
# -*- tcl -*-
# Tests for the find function.
#
# Sourcing this file into Tcl runs the tests and generates output for errors.
# No output means no errors were found.
#
# Copyright (c) 1998-2000 by Ajuba Solutions.
# Copyright (c) 2001 by ActiveState Tool Corp.
# Copyright (c) 2005-2007 by Andreas Kupries <[email protected]>
# All rights reserved.
#
# RCS: @(#) $Id: fileutil.test,v 1.56 2009/10/06 20:07:18 andreas_kupries Exp $





# -------------------------------------------------------------------------

source [file join \
	[file dirname [file dirname [file join [pwd] [info script]]]] \
	devtools testutilities.tcl]









|



>
>
>
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# -*- tcl -*-
# Tests for the find function.
#
# Sourcing this file into Tcl runs the tests and generates output for errors.
# No output means no errors were found.
#
# Copyright (c) 1998-2000 by Ajuba Solutions.
# Copyright (c) 2001 by ActiveState Tool Corp.
# Copyright (c) 2005-2013 by Andreas Kupries <[email protected]>
# All rights reserved.
#
# RCS: @(#) $Id: fileutil.test,v 1.56 2009/10/06 20:07:18 andreas_kupries Exp $

# TODO: Bug [8b317b4a63]: Create test cases for this bug. This
# requires the use of a custom VFS as the native filesystem does not
# contain the bug we are guarding ourselves against.

# -------------------------------------------------------------------------

source [file join \
	[file dirname [file dirname [file join [pwd] [info script]]]] \
	devtools testutilities.tcl]

Changes to modules/fileutil/pkgIndex.tcl.

1
2
3
4
5
6
7
8
9
if {![package vsatisfies [package provide Tcl] 8.2]} {return}
package ifneeded fileutil 1.14.5 [list source [file join $dir fileutil.tcl]]

if {![package vsatisfies [package provide Tcl] 8.3]} {return}
package ifneeded fileutil::traverse 0.4.3 [list source [file join $dir traverse.tcl]]

if {![package vsatisfies [package provide Tcl] 8.4]} {return}
package ifneeded fileutil::multi     0.1   [list source [file join $dir multi.tcl]]
package ifneeded fileutil::multi::op 0.5.3 [list source [file join $dir multiop.tcl]]

|







1
2
3
4
5
6
7
8
9
if {![package vsatisfies [package provide Tcl] 8.2]} {return}
package ifneeded fileutil 1.14.6 [list source [file join $dir fileutil.tcl]]

if {![package vsatisfies [package provide Tcl] 8.3]} {return}
package ifneeded fileutil::traverse 0.4.3 [list source [file join $dir traverse.tcl]]

if {![package vsatisfies [package provide Tcl] 8.4]} {return}
package ifneeded fileutil::multi     0.1   [list source [file join $dir multi.tcl]]
package ifneeded fileutil::multi::op 0.5.3 [list source [file join $dir multiop.tcl]]