check the original image for existence before os.Stat

Signed-off-by: Cocoa <0xbbc@0xbbc.com>
This commit is contained in:
Cocoa 2020-02-26 00:50:19 +08:00
parent 2b40d844a4
commit 735b7d2cda
No known key found for this signature in database
GPG Key ID: 9821F9625A97231D

View File

@ -100,6 +100,14 @@ func main() {
// /path/to
DirPath := path.Dir(ImgPath)
// Check the original image for existence
OriginalImgExists := imageExists(ImgAbsolutePath)
if !OriginalImgExists {
c.Send("File not found!")
c.SendStatus(404)
return
}
// 1582558990
STAT, err := os.Stat(ImgAbsolutePath)
if err != nil {
@ -131,7 +139,7 @@ func main() {
}
// Check the original image for existence
if !imageExists(ImgAbsolutePath) {
if !OriginalImgExists {
// The original image doesn't exist, check the webp image, delete if processed.
if imageExists(WebpAbsolutePath) {
os.Remove(WebpAbsolutePath)