sharanggupta opened a new pull request, #798:
URL: https://github.com/apache/commons-vfs/pull/798

   Fixes [VFS-714](https://issues.apache.org/jira/browse/VFS-714). This builds 
on #797, which makes the `FilesCache` tests run again, so the first commit here 
is the one from #797.
   
   **What**
   
   With a `NullFilesCache`, `deleteAll()` on a folder that has children deletes 
the files but not the folders. `delete(FileSelector)` deletes the files that 
`findFiles()` returns, children first, and skips a folder when `getChildren()` 
is not empty, which is how a selector that leaves some children keeps their 
folder. Deleting a child notifies its parent through `notifyParent()`, which 
finds the parent object through its `parent` field or `FilesCache.getFile()`. 
With a `NullFilesCache` neither of them is the folder object that `findFiles()` 
listed, so that object keeps its cached children. The folder is then skipped as 
non-empty, although it is empty on the file system.
   
   **How**
   
   `delete(FileSelector)` now asks a small `hasChildren()` helper whether a 
folder still has children. When the cached children of the folder object are 
not empty, the helper refreshes the object and lists the children again before 
deciding. With the caches that keep one object per file, the cache is already 
up to date and empty after its children were deleted, so there is no extra 
listing. Only a folder whose cached children are not empty is listed again: a 
stale folder as with a `NullFilesCache`, or a folder that the selector does not 
empty, which stays skipped.
   
   I considered refreshing every folder before the check. That would also catch 
a folder whose cached children are empty but which another client filled in the 
meantime. But it would add one listing per deleted folder to every 
`deleteAll()`, which matters on SFTP, FTP, WebDAV or HDFS. That case is not 
part of this issue and behaves as on master.
   
   **Tests**
   
   `AbstractFilesCacheTestsBase.testDeleteAll` creates a folder with a file and 
a subfolder holding another file, calls `deleteAll()` on the folder and checks 
that it deleted the 4 entries and that the folder no longer exists. It runs for 
all five `FilesCache` suites from #797. On master only `NullFilesCacheTest` 
fails (`expected: <4> but was: <2>`, the two files). With this change all five 
pass.
   
   The default Maven goal passes locally on Java 17.
   
   Before you push a pull request, review this list:
   
   - [x] Read the [contribution guidelines](CONTRIBUTING.md) for this project.
   - [x] Read the [ASF Generative Tooling 
Guidance](https://www.apache.org/legal/generative-tooling.html) if you use 
Artificial Intelligence (AI).
   - [x] I used AI to create any part of, or all of, this pull request. Which 
AI tool was used to create this pull request, and to what extent did it 
contribute? Claude (Anthropic) helped analyse the bug and draft the change and 
test; I reviewed them against the code and ran the build.
   - [x] Run a successful build using the default 
[Maven](https://maven.apache.org/) goal with `mvn`; that's `mvn` on the command 
line by itself.
   - [x] Write unit tests that match behavioral changes, where the tests fail 
if the changes to the runtime are not applied. This may not always be possible, 
but it is a best practice.
   - [x] Write a pull request description that is detailed enough to understand 
what the pull request does, how, and why.
   - [x] Each commit in the pull request should have a meaningful subject line 
and body. Note that a maintainer may squash commits during the merge process.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to