Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
ackley_mc
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Torda, Prof. Dr. Andrew Ernest
ackley_mc
Commits
d40bcaf8
Commit
d40bcaf8
authored
3 years ago
by
Andrew E. Torda
Browse files
Options
Downloads
Patches
Plain Diff
Very verbose error message, but still cannot resolve the problem.
parent
5fbcc2ec
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
mc_work/dorun.go
+24
-15
24 additions, 15 deletions
mc_work/dorun.go
with
24 additions
and
15 deletions
mc_work/dorun.go
+
24
−
15
View file @
d40bcaf8
...
@@ -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,26 +78,34 @@ func fExists (name string) bool {
...
@@ -77,26 +78,34 @@ 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, I cannot overwrite an existing file. To be very exact, the
// O_CREATE fails if a file exists. O_TRUNC also fails.
// 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
)
{
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.
Tried setting pemissions on directory %s, but failed:
%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.
var
t
string
if
t
,
err
=
filepath
.
Abs
(
name
);
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"cannot work out path %w"
,
err
)
}
d
:=
filepath
.
Dir
(
t
)
e
:=
os
.
Chmod
(
d
,
0200
)
if
e
!=
nil
{
return
nil
,
fmt
.
Errorf
(
longErr
,
name
,
d
,
e
)
}
if
!
fExists
(
name
)
{
// does not exist, but we have a real error.
}
else
{
// the file exists
return
nil
,
err
// Return original error
fmt
.
Println
(
"file exists, what to do ?"
)
}
// Next step try to remove original file
if
e
:=
os
.
Remove
(
name
);
e
!=
nil
{
return
nil
,
fmt
.
Errorf
(
rErr
,
name
,
e
)
}
if
f
,
err
=
os
.
Create
(
name
);
err
==
nil
{
// second attempt, after removing name
return
f
,
nil
}
}
return
nil
,
err
return
nil
,
err
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment