Skip to content

storage.Delete() fails to delete non-empty folders #5691

Open
@rad756

Description

@rad756

Checklist

  • I have searched the issue tracker for open issues that relate to the same problem, before opening a new one.
  • This issue only relates to a single bug. I will open new issues for any other problems.

Describe the bug

Delete function will error out when trying to delete a folder that contains files/folders.

How to reproduce

Create a folder, within that folder create a file.
Then try to delete it with storage.Delete

Screenshots

No response

Example code

package main

import (
	"fmt"

	"fyne.io/fyne/v2"
	"fyne.io/fyne/v2/app"

	"fyne.io/fyne/v2/storage"
)

func main() {
	a := app.NewWithID("delete-recursive-test")

	createTestData(a)

	deleteTestData(a)
}

func createTestData(a fyne.App) {
	// create empty folder
	path, _ := storage.Child(a.Storage().RootURI(), "EmptyFolder")
	_ = storage.CreateListable(path)

	// create folder with data
	path, _ = storage.Child(a.Storage().RootURI(), "DataFolder")
	_ = storage.CreateListable(path)

	path, _ = storage.Child(path, "data.txt")
	file, _ := storage.Writer(path)
	file.Write([]byte{})

}

func deleteTestData(a fyne.App) {
	path, _ := storage.Child(a.Storage().RootURI(), "EmptyFolder")
	err := storage.Delete(path)

	fmt.Println(err)

	path, _ = storage.Child(a.Storage().RootURI(), "DataFolder")
	err = storage.Delete(path)

	fmt.Println(err)
}

Fyne version

2.6.0

Go compiler version

1.24.1

Operating system and version

Linux

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    unverifiedA bug that has been reported but not verified

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions