grim/devweb
Clone
Summary
Browse
Changes
Graph
Remove some components by just merging them into the templates of their parents
draft
2021-01-25, Gary Kramlich
2bcd291942a3
Remove some components by just merging them into the templates of their parents
package
storage
import
(
"fmt"
"os"
"path/filepath"
log
"github.com/sirupsen/logrus"
)
type
Storage
struct
{
path
string
}
func
Create
(
path
string
)
(
Storage
,
error
)
{
log
.
Infof
(
"setting up storage path %q\n"
,
path
)
info
,
err
:=
os
.
Stat
(
path
)
if
os
.
IsNotExist
(
err
)
{
// path doesn't exist, so create it
if
err
:=
os
.
MkdirAll
(
path
,
0755
);
err
!=
nil
{
return
Storage
{},
err
}
}
else
{
// The path exists so lets make sure it's a directory.
if
!
info
.
IsDir
()
{
err
:=
fmt
.
Errorf
(
"storage path %q exists and is not a directory"
,
path
)
return
Storage
{},
err
}
}
return
Storage
{
path
:
path
},
nil
}
func
(
s
Storage
)
Remove
(
path
string
)
error
{
realPath
:=
filepath
.
Join
(
s
.
path
,
path
)
return
os
.
RemoveAll
(
realPath
)
}