Implementation of File Exists Function; Delete FileInfos upon Permanent User Delete (#8958)
Check if file was deleted on FS Warning message if file couldnt be removed
Этот коммит содержится в:
коммит произвёл
Harrison Healey
родитель
fc158fce90
Коммит
ecefa6cdd1
@@ -70,6 +70,14 @@ func (a *App) ReadFile(path string) ([]byte, *model.AppError) {
|
||||
return backend.ReadFile(path)
|
||||
}
|
||||
|
||||
func (a *App) FileExists(path string) (bool, *model.AppError) {
|
||||
backend, err := a.FileBackend()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return backend.FileExists(path)
|
||||
}
|
||||
|
||||
func (a *App) MoveFile(oldPath, newPath string) *model.AppError {
|
||||
backend, err := a.FileBackend()
|
||||
if err != nil {
|
||||
|
||||
27
app/user.go
27
app/user.go
@@ -1288,6 +1288,33 @@ func (a *App) PermanentDeleteUser(user *model.User) *model.AppError {
|
||||
return result.Err
|
||||
}
|
||||
|
||||
fchan := a.Srv.Store.FileInfo().GetForUser(user.Id)
|
||||
var infos []*model.FileInfo
|
||||
if result := <-fchan; result.Err != nil {
|
||||
mlog.Warn("Error getting file list for user from FileInfoStore")
|
||||
} else {
|
||||
infos = result.Data.([]*model.FileInfo)
|
||||
for _, info := range infos {
|
||||
res, err := a.FileExists(info.Path)
|
||||
|
||||
if err != nil {
|
||||
mlog.Warn(fmt.Sprintf("Error checking existence of file '%s': %s", info.Path, err))
|
||||
continue
|
||||
}
|
||||
|
||||
if res {
|
||||
a.RemoveFile(info.Path)
|
||||
} else {
|
||||
mlog.Warn(fmt.Sprintf("Unable to remove file '%s': %s", info.Path, err))
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if result := <-a.Srv.Store.FileInfo().PermanentDeleteByUser(user.Id); result.Err != nil {
|
||||
return result.Err
|
||||
}
|
||||
|
||||
if result := <-a.Srv.Store.User().PermanentDelete(user.Id); result.Err != nil {
|
||||
return result.Err
|
||||
}
|
||||
|
||||
@@ -480,3 +480,47 @@ func TestCreateUserWithToken(t *testing.T) {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestPermanentDeleteUser(t *testing.T) {
|
||||
th := Setup().InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
b := []byte("testimage")
|
||||
|
||||
finfo, err := th.App.DoUploadFile(time.Now(), th.BasicTeam.Id, th.BasicChannel.Id, th.BasicUser.Id, "testfile.txt", b)
|
||||
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
t.Fatal("Unable to upload file")
|
||||
}
|
||||
|
||||
err = th.App.PermanentDeleteUser(th.BasicUser)
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
t.Fatal("Unable to delete user")
|
||||
}
|
||||
|
||||
res, err := th.App.FileExists(finfo.Path)
|
||||
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
t.Fatal("Unable to check whether file exists")
|
||||
}
|
||||
|
||||
if res {
|
||||
t.Log(err)
|
||||
t.Fatal("File was not deleted on FS")
|
||||
}
|
||||
|
||||
finfo, err = th.App.GetFileInfo(finfo.Id)
|
||||
|
||||
if finfo != nil {
|
||||
t.Log(err)
|
||||
t.Fatal("Unable to find finfo")
|
||||
}
|
||||
|
||||
if err == nil {
|
||||
t.Log(err)
|
||||
t.Fatal("GetFileInfo after DeleteUser is nil")
|
||||
}
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user