summaryrefslogtreecommitdiffstats
path: root/store/sql_file_info_store.go
diff options
context:
space:
mode:
authorGeorge Goldberg <george@gberg.me>2017-08-25 15:38:13 +0100
committerHarrison Healey <harrisonmhealey@gmail.com>2017-08-25 10:38:13 -0400
commit50fc6e1e9e8d286fd6a406cef75e48a28f9427ad (patch)
tree0689de640729194b9a123ec8bfef36cbecd8cefd /store/sql_file_info_store.go
parent99acf6106833a2186c0f7e07985feac5d9c25de1 (diff)
downloadchat-50fc6e1e9e8d286fd6a406cef75e48a28f9427ad.tar.gz
chat-50fc6e1e9e8d286fd6a406cef75e48a28f9427ad.tar.bz2
chat-50fc6e1e9e8d286fd6a406cef75e48a28f9427ad.zip
PLT-???? Prepare file upload infrastructure for Data Retention. (#7266)
* Prepare file upload infrastructure for Data Retention. This commit prepares the file upload infrastructure for the data retention feature that is under construction. Changes are: * Move file management code to utils to allow access to it from jobs. * From now on, store all file uploads in a top level folder which is the date of the day on which they were uploaded. This commit is based on Harrison Healey's branch, but updated to work with the latest master. * Use NewAppError
Diffstat (limited to 'store/sql_file_info_store.go')
-rw-r--r--store/sql_file_info_store.go40
1 files changed, 31 insertions, 9 deletions
diff --git a/store/sql_file_info_store.go b/store/sql_file_info_store.go
index 3fe62121c..4bf6c9c73 100644
--- a/store/sql_file_info_store.go
+++ b/store/sql_file_info_store.go
@@ -97,7 +97,7 @@ func (fs SqlFileInfoStore) Get(id string) StoreChannel {
if err == sql.ErrNoRows {
result.Err = model.NewAppError("SqlFileInfoStore.Get", "store.sql_file_info.get.app_error", nil, "id="+id+", "+err.Error(), http.StatusNotFound)
} else {
- result.Err = model.NewLocAppError("SqlFileInfoStore.Get", "store.sql_file_info.get.app_error", nil, "id="+id+", "+err.Error())
+ result.Err = model.NewAppError("SqlFileInfoStore.Get", "store.sql_file_info.get.app_error", nil, "id="+id+", "+err.Error(), http.StatusInternalServerError)
}
} else {
result.Data = info
@@ -127,7 +127,7 @@ func (fs SqlFileInfoStore) GetByPath(path string) StoreChannel {
Path = :Path
AND DeleteAt = 0
LIMIT 1`, map[string]interface{}{"Path": path}); err != nil {
- result.Err = model.NewLocAppError("SqlFileInfoStore.GetByPath", "store.sql_file_info.get_by_path.app_error", nil, "path="+path+", "+err.Error())
+ result.Err = model.NewAppError("SqlFileInfoStore.GetByPath", "store.sql_file_info.get_by_path.app_error", nil, "path="+path+", "+err.Error(), http.StatusInternalServerError)
} else {
result.Data = info
}
@@ -139,7 +139,7 @@ func (fs SqlFileInfoStore) GetByPath(path string) StoreChannel {
return storeChannel
}
-func (s SqlFileInfoStore) InvalidateFileInfosForPostCache(postId string) {
+func (fs SqlFileInfoStore) InvalidateFileInfosForPostCache(postId string) {
fileInfoCache.Remove(postId)
}
@@ -190,8 +190,8 @@ func (fs SqlFileInfoStore) GetForPost(postId string, readFromMaster bool, allowF
AND DeleteAt = 0
ORDER BY
CreateAt`, map[string]interface{}{"PostId": postId}); err != nil {
- result.Err = model.NewLocAppError("SqlFileInfoStore.GetForPost",
- "store.sql_file_info.get_for_post.app_error", nil, "post_id="+postId+", "+err.Error())
+ result.Err = model.NewAppError("SqlFileInfoStore.GetForPost",
+ "store.sql_file_info.get_for_post.app_error", nil, "post_id="+postId+", "+err.Error(), http.StatusInternalServerError)
} else {
if len(infos) > 0 {
fileInfoCache.AddWithExpiresInSecs(postId, infos, FILE_INFO_CACHE_SEC)
@@ -221,8 +221,8 @@ func (fs SqlFileInfoStore) AttachToPost(fileId, postId string) StoreChannel {
WHERE
Id = :Id
AND PostId = ''`, map[string]interface{}{"PostId": postId, "Id": fileId}); err != nil {
- result.Err = model.NewLocAppError("SqlFileInfoStore.AttachToPost",
- "store.sql_file_info.attach_to_post.app_error", nil, "post_id="+postId+", file_id="+fileId+", err="+err.Error())
+ result.Err = model.NewAppError("SqlFileInfoStore.AttachToPost",
+ "store.sql_file_info.attach_to_post.app_error", nil, "post_id="+postId+", file_id="+fileId+", err="+err.Error(), http.StatusInternalServerError)
}
storeChannel <- result
@@ -245,8 +245,8 @@ func (fs SqlFileInfoStore) DeleteForPost(postId string) StoreChannel {
DeleteAt = :DeleteAt
WHERE
PostId = :PostId`, map[string]interface{}{"DeleteAt": model.GetMillis(), "PostId": postId}); err != nil {
- result.Err = model.NewLocAppError("SqlFileInfoStore.DeleteForPost",
- "store.sql_file_info.delete_for_post.app_error", nil, "post_id="+postId+", err="+err.Error())
+ result.Err = model.NewAppError("SqlFileInfoStore.DeleteForPost",
+ "store.sql_file_info.delete_for_post.app_error", nil, "post_id="+postId+", err="+err.Error(), http.StatusInternalServerError)
} else {
result.Data = postId
}
@@ -257,3 +257,25 @@ func (fs SqlFileInfoStore) DeleteForPost(postId string) StoreChannel {
return storeChannel
}
+
+func (fs SqlFileInfoStore) PermanentDelete(fileId string) StoreChannel {
+ storeChannel := make(StoreChannel, 1)
+
+ go func() {
+ result := StoreResult{}
+
+ if _, err := fs.GetMaster().Exec(
+ `DELETE FROM
+ FileInfo
+ WHERE
+ Id = :FileId`, map[string]interface{}{"FileId": fileId}); err != nil {
+ result.Err = model.NewAppError("SqlFileInfoStore.PermanentDelete",
+ "store.sql_file_info.permanent_delete.app_error", nil, "file_id="+fileId+", err="+err.Error(), http.StatusInternalServerError)
+ }
+
+ storeChannel <- result
+ close(storeChannel)
+ }()
+
+ return storeChannel
+}