aboutsummaryrefslogtreecommitdiff
path: root/mediaapi/fileutils
diff options
context:
space:
mode:
authorRyan W <twentybitdev@gmail.com>2021-09-08 17:31:03 +0100
committerGitHub <noreply@github.com>2021-09-08 17:31:03 +0100
commita624eab309ee6ee7b3540dfba884a42c9a4f4ad9 (patch)
tree92ec39ba2d0f512891dcb20635ee9bc660b45b18 /mediaapi/fileutils
parent7dc8fb1fe780888d5758bf665949e9e09d21e56a (diff)
- Removed double imports (#1989)
- Lower cased error messages Signed-off-by: Ryan Whittington <twentybitdev@gmail.com> Co-authored-by: kegsay <kegan@matrix.org>
Diffstat (limited to 'mediaapi/fileutils')
-rw-r--r--mediaapi/fileutils/fileutils.go24
1 files changed, 12 insertions, 12 deletions
diff --git a/mediaapi/fileutils/fileutils.go b/mediaapi/fileutils/fileutils.go
index 7309cb88..754e4644 100644
--- a/mediaapi/fileutils/fileutils.go
+++ b/mediaapi/fileutils/fileutils.go
@@ -37,10 +37,10 @@ import (
// For example, if Base64Hash is 'qwerty', the path will be 'q/w/erty/file'.
func GetPathFromBase64Hash(base64Hash types.Base64Hash, absBasePath config.Path) (string, error) {
if len(base64Hash) < 3 {
- return "", fmt.Errorf("Invalid filePath (Base64Hash too short - min 3 characters): %q", base64Hash)
+ return "", fmt.Errorf("invalid filePath (Base64Hash too short - min 3 characters): %q", base64Hash)
}
if len(base64Hash) > 255 {
- return "", fmt.Errorf("Invalid filePath (Base64Hash too long - max 255 characters): %q", base64Hash)
+ return "", fmt.Errorf("invalid filePath (Base64Hash too long - max 255 characters): %q", base64Hash)
}
filePath, err := filepath.Abs(filepath.Join(
@@ -51,14 +51,14 @@ func GetPathFromBase64Hash(base64Hash types.Base64Hash, absBasePath config.Path)
"file",
))
if err != nil {
- return "", fmt.Errorf("Unable to construct filePath: %w", err)
+ return "", fmt.Errorf("unable to construct filePath: %w", err)
}
// check if the absolute absBasePath is a prefix of the absolute filePath
// if so, no directory escape has occurred and the filePath is valid
// Note: absBasePath is already absolute
if !strings.HasPrefix(filePath, string(absBasePath)) {
- return "", fmt.Errorf("Invalid filePath (not within absBasePath %v): %v", absBasePath, filePath)
+ return "", fmt.Errorf("invalid filePath (not within absBasePath %v): %v", absBasePath, filePath)
}
return filePath, nil
@@ -102,7 +102,7 @@ func MoveFileWithHashCheck(tmpDir types.Path, mediaMetadata *types.MediaMetadata
func RemoveDir(dir types.Path, logger *log.Entry) {
dirErr := os.RemoveAll(string(dir))
if dirErr != nil {
- logger.WithError(dirErr).WithField("dir", dir).Warn("Failed to remove directory")
+ logger.WithError(dirErr).WithField("dir", dir).Warn("failed to remove directory")
}
}
@@ -153,11 +153,11 @@ func moveFile(src types.Path, dst types.Path) error {
err := os.MkdirAll(dstDir, 0770)
if err != nil {
- return fmt.Errorf("Failed to make directory: %w", err)
+ return fmt.Errorf("failed to make directory: %w", err)
}
err = os.Rename(string(src), string(dst))
if err != nil {
- return fmt.Errorf("Failed to move directory: %w", err)
+ return fmt.Errorf("failed to move directory: %w", err)
}
return nil
}
@@ -165,11 +165,11 @@ func moveFile(src types.Path, dst types.Path) error {
func createTempFileWriter(absBasePath config.Path) (*bufio.Writer, *os.File, types.Path, error) {
tmpDir, err := createTempDir(absBasePath)
if err != nil {
- return nil, nil, "", fmt.Errorf("Failed to create temp dir: %w", err)
+ return nil, nil, "", fmt.Errorf("failed to create temp dir: %w", err)
}
writer, tmpFile, err := createFileWriter(tmpDir)
if err != nil {
- return nil, nil, "", fmt.Errorf("Failed to create file writer: %w", err)
+ return nil, nil, "", fmt.Errorf("failed to create file writer: %w", err)
}
return writer, tmpFile, tmpDir, nil
}
@@ -178,11 +178,11 @@ func createTempFileWriter(absBasePath config.Path) (*bufio.Writer, *os.File, typ
func createTempDir(baseDirectory config.Path) (types.Path, error) {
baseTmpDir := filepath.Join(string(baseDirectory), "tmp")
if err := os.MkdirAll(baseTmpDir, 0770); err != nil {
- return "", fmt.Errorf("Failed to create base temp dir: %w", err)
+ return "", fmt.Errorf("failed to create base temp dir: %w", err)
}
tmpDir, err := ioutil.TempDir(baseTmpDir, "")
if err != nil {
- return "", fmt.Errorf("Failed to create temp dir: %w", err)
+ return "", fmt.Errorf("failed to create temp dir: %w", err)
}
return types.Path(tmpDir), nil
}
@@ -194,7 +194,7 @@ func createFileWriter(directory types.Path) (*bufio.Writer, *os.File, error) {
filePath := filepath.Join(string(directory), "content")
file, err := os.Create(filePath)
if err != nil {
- return nil, nil, fmt.Errorf("Failed to create file: %w", err)
+ return nil, nil, fmt.Errorf("failed to create file: %w", err)
}
return bufio.NewWriter(file), file, nil