Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to overwrite file when using dialog.ShowFileSave #1168

Closed
PucklaJ opened this issue Jul 6, 2020 · 3 comments
Closed

Unable to overwrite file when using dialog.ShowFileSave #1168

PucklaJ opened this issue Jul 6, 2020 · 3 comments
Labels
blocker Items that would block a forthcoming release bug Something isn't working
Milestone

Comments

@PucklaJ
Copy link
Contributor

PucklaJ commented Jul 6, 2020

Describe the bug:

I am working on an application that exports some generated data as a .csv file. To do this I am using dialog.ShowFileSave(). If the file doesn't exist it works fine, but if it does URIWriteCloser.Write returns the error "Access denied".
You can work around this by retrieving the file name and then using os.Create, but it would be better to use the official way.

To Reproduce:

Steps To Reproduce:

  1. Write to a file using dialog.ShowFileSave
  2. Write to the same file again

Example code:

package main

import (
	"bytes"
	"fmt"

	"fyne.io/fyne"
	"fyne.io/fyne/app"
	"fyne.io/fyne/dialog"
	"fyne.io/fyne/widget"
)

func main() {
	a := app.New()
	w := a.NewWindow("Overwrite Bug")

	t := widget.NewEntry()

	w.SetContent(
		widget.NewHBox(
			t,
			widget.NewButton("Save", func() {
				dialog.ShowFileSave(func(writer fyne.URIWriteCloser, err error) {
					if writer == nil {
						return
					}
					if err != nil {
						panic(err)
					}
					defer writer.Close()
					buffer := bytes.NewBufferString(t.Text)
					n, err := writer.Write(buffer.Bytes())
					if err != nil {
						// This panic is called
						panic(err)
					}
					fmt.Println("Wrote", n, "bytes")
				}, w)
			}),
		),
	)

	w.ShowAndRun()
}

Device:

  • OS: Windows 10
  • Version: 2004
  • Go version: 1.14.4
  • Fyne version: 1.3.0
@andydotxyz andydotxyz added the bug Something isn't working label Jul 6, 2020
@andydotxyz andydotxyz added this to the 1.3.x milestone Jul 6, 2020
@andydotxyz
Copy link
Member

Well caught, you are quite right that this should work as expected.
Did the dialog prompt you to confirm the overwrite?

@PucklaJ
Copy link
Contributor Author

PucklaJ commented Jul 7, 2020

Yes. It prompted me to confirm the overwrite, but as mentioned above it didn't work.

@andydotxyz andydotxyz added the blocker Items that would block a forthcoming release label Jul 7, 2020
andydotxyz added a commit to andydotxyz/fyne that referenced this issue Jul 7, 2020
This will truncate existing files.

Fixes fyne-io#1168
@andydotxyz
Copy link
Member

Thanks for the info, I managed to get the fix slipped into the release today :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocker Items that would block a forthcoming release bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants