[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Help-smalltalk] Re: walking a directory tree
From: |
Paolo Bonzini |
Subject: |
[Help-smalltalk] Re: walking a directory tree |
Date: |
Fri, 09 Jan 2009 10:09:34 +0100 |
User-agent: |
Thunderbird 2.0.0.19 (Macintosh/20081209) |
> The attached patch fixes the above misfeature.
Wrong patch attached, this is the correct one.
Paolo
diff --git a/kernel/FilePath.st b/kernel/FilePath.st
index 54a14dc..f35156e 100644
--- a/kernel/FilePath.st
+++ b/kernel/FilePath.st
@@ -736,7 +736,10 @@ size and timestamps.'>
all [
"Return a decorator of the receiver that will provide recursive
- descent into directories for iteration methods."
+ descent into directories for iteration methods. Furthermore,
+ iteration on the returned wrapper will not include '.' or '..'
+ directory entries, and will include the receiver (directly, not
+ via '.')."
<category: 'decoration'>
^Kernel.RecursiveFileWrapper on: self
@@ -813,7 +816,9 @@ size and timestamps.'>
do: aBlock [
"Evaluate aBlock once for each file in the directory represented by the
- receiver, passing its name."
+ receiver, passing a FilePath object (or a subclass) to it. It depends
+ on the subclass whether iteration will include the '.' and '..'
+ directory entries."
<category: 'enumerating'>
self namesDo: [ :name |
@@ -822,7 +827,8 @@ size and timestamps.'>
namesDo: aBlock [
"Evaluate aBlock once for each file in the directory represented by the
- receiver, passing its name."
+ receiver, passing its name. It depends on the subclass whether
+ iteration will include the '.' and '..' directory entries."
<category: 'enumerating'>
self subclassResponsibility
diff --git a/kernel/VFS.st b/kernel/VFS.st
index 9a01b02..d344a04 100644
--- a/kernel/VFS.st
+++ b/kernel/VFS.st
@@ -352,15 +352,16 @@ VFS.FileWrapper subclass: RecursiveFileWrapper [
"Same as the wrapped #do:, but reuses the file object for efficiency."
<category: 'enumerating'>
+ aBlock value: self file.
self file namesDo:
[:name |
- | f |
- f := self at: name.
- aBlock value: f.
- f isDirectory
- ifTrue:
- [((#('.' '..') includes: name) or: [f isSymbolicLink])
- ifFalse: [f do: aBlock]]]
+ | f period |
+ period := #('.' '..') includes: name.
+ period ifFalse: [
+ f := self at: name.
+ aBlock value: f file.
+ (f isDirectory and: [f isSymbolicLink not])
+ ifTrue: [f do: aBlock]]]
]
namesDo: aBlock prefixLength: anInteger [
@@ -371,15 +372,15 @@ VFS.FileWrapper subclass: RecursiveFileWrapper [
<category: 'private'>
self file namesDo:
[:name |
- | f |
- f := self at: name.
- aBlock value: (f asString copyFrom: anInteger).
- f isDirectory
- ifTrue:
- [((#('.' '..') includes: name) or: [f isSymbolicLink])
- ifFalse: [f
- namesDo: aBlock
- prefixLength: anInteger ]]]
+ | f period |
+ period := #('.' '..') includes: name.
+ period ifFalse: [
+ f := self at: name.
+ aBlock value: (f asString copyFrom: anInteger).
+ (f isDirectory and: [f isSymbolicLink not])
+ ifTrue: [f
+ namesDo: aBlock
+ prefixLength: anInteger ]]]
]
namesDo: aBlock [
@@ -387,6 +388,7 @@ VFS.FileWrapper subclass: RecursiveFileWrapper [
tree recursively."
<category: 'enumerating'>
+ aBlock value: '.'.
self namesDo: aBlock prefixLength: self asString size + 2
]
@@ -422,7 +424,7 @@ VFS.FileWrapper subclass: RecursiveFileWrapper [
self isDirectory ifFalse: [
^super lastAccessTime: accessDateTime lastModifyTime:
modifyDateTime ].
self do: [ :each |
- each file lastAccessTime: accessDateTime lastModifyTime:
modifyDateTime ]
+ each lastAccessTime: accessDateTime lastModifyTime: modifyDateTime ]
]
owner: ownerString group: groupString [
@@ -434,7 +436,7 @@ VFS.FileWrapper subclass: RecursiveFileWrapper [
"These special calls cache the uid and gid to avoid repeated lookups."
[
File setOwnerFor: nil owner: ownerString group: groupString.
- self do: [ :each | each file owner: ownerString group: groupString
]
+ self do: [ :each | each owner: ownerString group: groupString ]
] ensure: [ File setOwnerFor: nil owner: nil group: nil ]
]
@@ -445,8 +447,7 @@ VFS.FileWrapper subclass: RecursiveFileWrapper [
<category: 'accessing'>
self isDirectory ifFalse: [ ^super mode: anInteger ].
- self do: [ :each |
- each isDirectory ifFalse: [ each file mode: anInteger ] ]
+ self do: [ :each | each isDirectory ifFalse: [ each mode: anInteger ] ]
]
fileMode: fMode directoryMode: dMode [
@@ -459,8 +460,7 @@ VFS.FileWrapper subclass: RecursiveFileWrapper [
super mode: dMode.
self isDirectory ifTrue: [
self do: [ :each |
- each file
- mode: (each isDirectory
+ each mode: (each isDirectory
ifTrue: [ dMode ]
ifFalse: [ fMode ]) ] ]
]
- [Help-smalltalk] walking a directory tree, Sean Allen, 2009/01/08
- Re: [Help-smalltalk] walking a directory tree, Paolo Bonzini, 2009/01/09
- Re: [Help-smalltalk] walking a directory tree, Sean Allen, 2009/01/09
- Re: [Help-smalltalk] walking a directory tree, Paolo Bonzini, 2009/01/09
- [Help-smalltalk] Re: walking a directory tree,
Paolo Bonzini <=
- [Help-smalltalk] Re: walking a directory tree, Sean Allen, 2009/01/10
- [Help-smalltalk] Re: walking a directory tree, Paolo Bonzini, 2009/01/11
- [Help-smalltalk] Re: walking a directory tree, Sean Allen, 2009/01/11
- [Help-smalltalk] Re: walking a directory tree, Paolo Bonzini, 2009/01/11
- [Help-smalltalk] Re: walking a directory tree, Paolo Bonzini, 2009/01/12
- [Help-smalltalk] Re: walking a directory tree, Sean Allen, 2009/01/12
- [Help-smalltalk] Re: walking a directory tree, Paolo Bonzini, 2009/01/12
- [Help-smalltalk] Re: walking a directory tree, Sean Allen, 2009/01/12
- Re: [Help-smalltalk] walking a directory tree, Sean Allen, 2009/01/09
- Re: [Help-smalltalk] walking a directory tree, Sean Allen, 2009/01/09