grim/convey

Add a .reviewboardrc file

2022-03-26, Gary Kramlich
8fea0c778f8e
Add a .reviewboardrc file
// Convey
// Copyright 2016-2020 Gary Kramlich <grim@reaperworld.com>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
// Package path provides utilities for handling filesystem paths and
// objects.
package fs
import (
"os"
"path/filepath"
"strings"
log "github.com/sirupsen/logrus"
)
type Directory struct {
path string
}
func NewDirectory(path string) (*Directory, error) {
if !strings.HasSuffix(path, "/") {
path += "/"
}
err := os.MkdirAll(path, 0700)
if err != nil {
return nil, err
}
return &Directory{path: path}, nil
}
func (d *Directory) Path() string {
return d.path
}
func (d *Directory) Import(src, dst string) error {
file, err := os.Stat(src)
if err != nil {
return err
}
realDst := filepath.Join(d.path, dst)
if file.IsDir() {
log.Debugf("importing directory %q to %q", src, realDst)
return copyDir(src, realDst, file.Mode())
}
log.Debugf("importing file %q to %q", src, realDst)
return copyFile(src, realDst, file.Mode())
}
func (d *Directory) Export(src, dst string) error {
realSrc := filepath.Join(d.path, src)
file, err := os.Stat(realSrc)
if err != nil {
return err
}
if file.IsDir() {
log.Debugf("exporting directory %q to %q", realSrc, dst)
return copyDir(realSrc, dst, file.Mode())
}
log.Debugf("exporting file %q to %q", realSrc, dst)
return copyFile(realSrc, dst, file.Mode())
}
func (d *Directory) Destroy() error {
return os.RemoveAll(d.path)
}