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

Merge branch 'windows_expt' into devel

parents a0570d0c 8c8e8880
Branches
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.
......
...@@ -11,6 +11,7 @@ import ( ...@@ -11,6 +11,7 @@ import (
"math" "math"
"math/rand" "math/rand"
"os" "os"
"path/filepath"
"sync" "sync"
"example.com/ackley_mc/ackley" "example.com/ackley_mc/ackley"
...@@ -68,7 +69,7 @@ func isNotSane(mcPrm *McPrm) error { ...@@ -68,7 +69,7 @@ func isNotSane(mcPrm *McPrm) error {
// It is part of the exercise, working around file permissions on windows // It is part of the exercise, working around file permissions on windows
func fExists(name string) bool { func fExists(name string) bool {
var err error var err error
if _, err := os.Stat (name); err == nil { if _, err = os.Stat(name); err == nil {
return true return true
} }
if errors.Is(err, fs.ErrNotExist) { if errors.Is(err, fs.ErrNotExist) {
...@@ -77,28 +78,32 @@ func fExists (name string) bool { ...@@ -77,28 +78,32 @@ func fExists (name string) bool {
return true return true
} }
// 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.
func createFix(name string) (*os.File, error) { func createFix(name string) (*os.File, error) {
var rErr = `Remove the file %s and try again. This only happens on windows: %w` longErr := `%s does not exist, but could not create it:
%w
Please run the program from somewhere other than %s`
existErr := `File exists, but unable to write to it:
%w`
var f *os.File var f *os.File
var err error var err error
if f, err = os.Create(name); err == nil { if f, err = os.Create(name); err == nil {
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 real error. var d string
return nil, err // Return original error if t, e := filepath.Abs(name); e != nil {
} // Next step try to remove original file return nil, fmt.Errorf("cannot work out path %w", e)
if e := os.Remove (name); e != nil { } else {
return nil, fmt.Errorf (rErr, name, e) d = filepath.Dir(t)
}
if _, e := os.Stat(d); e != nil {
return nil, fmt.Errorf("parent directory %s is broken %w", d, err)
} }
if f, err = os.Create(name); err == nil { // second attempt, after removing name return nil, fmt.Errorf(longErr, name, err, d)
return f, nil
} }
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