Fix renaming to correctly create the base files if missing
This commit is contained in:
parent
d60b2d6163
commit
233cefd129
|
@ -61,6 +61,8 @@ func (e *RequestError) AbortWithStatus(status int, c *gin.Context) {
|
||||||
// If this error is because the resource does not exist, we likely do not need to log
|
// If this error is because the resource does not exist, we likely do not need to log
|
||||||
// the error anywhere, just return a 404 and move on with our lives.
|
// the error anywhere, just return a 404 and move on with our lives.
|
||||||
if os.IsNotExist(e.Err) {
|
if os.IsNotExist(e.Err) {
|
||||||
|
e.logger().WithField("error", e.Err).Debug("encountered os.IsNotExist error while handling request")
|
||||||
|
|
||||||
c.AbortWithStatusJSON(http.StatusNotFound, gin.H{
|
c.AbortWithStatusJSON(http.StatusNotFound, gin.H{
|
||||||
"error": "The requested resource was not found on the system.",
|
"error": "The requested resource was not found on the system.",
|
||||||
})
|
})
|
||||||
|
|
|
@ -385,6 +385,20 @@ func (fs *Filesystem) Rename(from string, to string) error {
|
||||||
return errors.WithStack(err)
|
return errors.WithStack(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if f, err := os.Stat(cleanedFrom); err != nil {
|
||||||
|
return errors.WithStack(err)
|
||||||
|
} else {
|
||||||
|
d := cleanedTo
|
||||||
|
if !f.IsDir() {
|
||||||
|
d = strings.TrimSuffix(d, path.Base(cleanedTo))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ensure that the directory we're moving into exists correctly on the system.
|
||||||
|
if mkerr := os.MkdirAll(d, 0644); mkerr != nil {
|
||||||
|
return errors.WithStack(mkerr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return os.Rename(cleanedFrom, cleanedTo)
|
return os.Rename(cleanedFrom, cleanedTo)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user