summaryrefslogtreecommitdiffstats
path: root/api/file.go
diff options
context:
space:
mode:
author=Corey Hulen <corey@hulen.com>2016-03-14 10:23:51 -0700
committer=Corey Hulen <corey@hulen.com>2016-03-14 10:23:51 -0700
commitea3f25924ea64a2dd1e73624c0d30824e1efb240 (patch)
treea4a2b2bdc37bd675fb89837713995ad44a27427b /api/file.go
parent397ebec88c2db3569efd77238bf877e976492d34 (diff)
parentbf7ae0711743926cfbb031675cc3320d7a942465 (diff)
downloadchat-ea3f25924ea64a2dd1e73624c0d30824e1efb240.tar.gz
chat-ea3f25924ea64a2dd1e73624c0d30824e1efb240.tar.bz2
chat-ea3f25924ea64a2dd1e73624c0d30824e1efb240.zip
Merge branch 'master' into PLT-2115
Diffstat (limited to 'api/file.go')
-rw-r--r--api/file.go35
1 files changed, 35 insertions, 0 deletions
diff --git a/api/file.go b/api/file.go
index 0011afd5b..9150e4bfe 100644
--- a/api/file.go
+++ b/api/file.go
@@ -547,6 +547,41 @@ func writeFile(f []byte, path string) *model.AppError {
return nil
}
+func moveFile(oldPath, newPath string) *model.AppError {
+ if utils.Cfg.FileSettings.DriverName == model.IMAGE_DRIVER_S3 {
+ fileData := make(chan []byte)
+ getFileAndForget(oldPath, fileData)
+ fileBytes := <-fileData
+
+ if fileBytes == nil {
+ return model.NewLocAppError("moveFile", "api.file.move_file.get_from_s3.app_error", nil, "")
+ }
+
+ var auth aws.Auth
+ auth.AccessKey = utils.Cfg.FileSettings.AmazonS3AccessKeyId
+ auth.SecretKey = utils.Cfg.FileSettings.AmazonS3SecretAccessKey
+
+ s := s3.New(auth, awsRegion())
+ bucket := s.Bucket(utils.Cfg.FileSettings.AmazonS3Bucket)
+
+ if err := bucket.Del(oldPath); err != nil {
+ return model.NewLocAppError("moveFile", "api.file.move_file.delete_from_s3.app_error", nil, err.Error())
+ }
+
+ if err := writeFile(fileBytes, newPath); err != nil {
+ return err
+ }
+ } else if utils.Cfg.FileSettings.DriverName == model.IMAGE_DRIVER_LOCAL {
+ if err := os.Rename(utils.Cfg.FileSettings.Directory+oldPath, utils.Cfg.FileSettings.Directory+newPath); err != nil {
+ return model.NewLocAppError("moveFile", "api.file.move_file.rename.app_error", nil, err.Error())
+ }
+ } else {
+ return model.NewLocAppError("moveFile", "api.file.move_file.configured.app_error", nil, "")
+ }
+
+ return nil
+}
+
func writeFileLocally(f []byte, path string) *model.AppError {
if err := os.MkdirAll(filepath.Dir(path), 0774); err != nil {
return model.NewLocAppError("writeFile", "api.file.write_file_locally.create_dir.app_error", nil, err.Error())