Skip to content
Snippets Groups Projects
Commit 8c8e8880 authored by Andrew E. Torda's avatar Andrew E. Torda
Browse files

More tests on the os.Create() problem under windows.

parent d40bcaf8
No related branches found
No related tags found
No related merge requests found
...@@ -38,6 +38,12 @@ The real documentation is in `go doc` format. ...@@ -38,6 +38,12 @@ The real documentation is in `go doc` format.
This is in csv format. For gnuplot, do not forget to `set datafile separator ','`. This is in csv format. For gnuplot, do not forget to `set datafile separator ','`.
# BUGS # BUGS
## Real Bugs
Only under windows: I use os.Create() to open a file for writing. In my "Documents" folder, the function call returns "The system cannot find the file specified". Note, this is when creating a file, not opening an existing one. I do not have any error when I run the program from a different directory. I did experiment with chmod() on the directory, but this (a) did not do anything and (b) only the bits set by 0200 are actually affected according to go's documentation.
## Non bugs
The UI toolkit is "fyne". It does not do charts, so we use go-chart which makes a png, which we can store in memory and feed to the fyne toolkit. Unfortunately, an svg file from go-chart causes fyne to choke. This means we are stuck with png. One day, one should try out the charting library which is based on fyne. The UI toolkit is "fyne". It does not do charts, so we use go-chart which makes a png, which we can store in memory and feed to the fyne toolkit. Unfortunately, an svg file from go-chart causes fyne to choke. This means we are stuck with png. One day, one should try out the charting library which is based on fyne.
The graphical interface follows no known style convention and looks like it was designed by a three-year old. The graphical interface follows no known style convention and looks like it was designed by a three-year old.
......
...@@ -79,14 +79,12 @@ func fExists(name string) bool { ...@@ -79,14 +79,12 @@ func fExists(name string) bool {
} }
// createFix is a wrapper around os.Create() which I seem to need for windows. // createFix is a wrapper around os.Create() which I seem to need for windows.
// On windows, I cannot overwrite an existing file. To be very exact, the // On windows, this fails if I am in my "Documents" directory.
// O_CREATE fails if a file exists. O_TRUNC also fails.
// Doing an open on the file gives the same, "The system cannot find the file specified"
// The calls fail, even if the file does not exist. It must be a problem
// with permissions on the directory, not the file.
func createFix(name string) (*os.File, error) { func createFix(name string) (*os.File, error) {
longErr := `%s does not exist, but could not create it. longErr := `%s does not exist, but could not create it:
Tried setting pemissions on directory %s, but failed: %w
Please run the program from somewhere other than %s`
existErr := `File exists, but unable to write to it:
%w` %w`
var f *os.File var f *os.File
var err error var err error
...@@ -94,20 +92,18 @@ Tried setting pemissions on directory %s, but failed: ...@@ -94,20 +92,18 @@ Tried setting pemissions on directory %s, but failed:
return f, nil // Most common path (no problem) return f, nil // Most common path (no problem)
} }
if !fExists(name) { // does not exist, but we have a problem. if !fExists(name) { // does not exist, but we have a problem.
var t string var d string
if t, err = filepath.Abs(name); err != nil { if t, e := filepath.Abs(name); e != nil {
return nil, fmt.Errorf("cannot work out path %w", err) return nil, fmt.Errorf("cannot work out path %w", e)
} else {
d = filepath.Dir(t)
} }
d := filepath.Dir(t) if _, e := os.Stat(d); e != nil {
e := os.Chmod(d, 0200) return nil, fmt.Errorf("parent directory %s is broken %w", d, err)
if e != nil {
return nil, fmt.Errorf(longErr, name, d, e)
} }
return nil, fmt.Errorf(longErr, name, err, d)
} else { // the file exists
fmt.Println("file exists, what to do ?")
} }
return nil, err return nil, fmt.Errorf(existErr, err) // The file exists..
} }
// setupRun does things like get the cooling rate, seed the random numbers. // setupRun does things like get the cooling rate, seed the random numbers.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment