[fix] validate if file exists in the file system
This commit is contained in:
parent
debc641f36
commit
fa94330dbf
1 changed files with 10 additions and 0 deletions
|
|
@ -22,6 +22,7 @@ import requests
|
|||
import requests.exceptions
|
||||
import StringIO
|
||||
import mimetypes, imghdr
|
||||
from frappe.utils import get_files_path
|
||||
|
||||
class FolderNotEmpty(frappe.ValidationError): pass
|
||||
|
||||
|
|
@ -66,6 +67,7 @@ class File(NestedSet):
|
|||
if self.is_new():
|
||||
self.validate_duplicate_entry()
|
||||
self.validate_folder()
|
||||
self.validate_file()
|
||||
self.set_folder_size()
|
||||
|
||||
def set_folder_size(self):
|
||||
|
|
@ -101,6 +103,14 @@ class File(NestedSet):
|
|||
not self.flags.ignore_folder_validate:
|
||||
frappe.throw(_("Folder is mandatory"))
|
||||
|
||||
def validate_file(self):
|
||||
if (self.file_url or "").startswith("/files/"):
|
||||
if not self.file_name:
|
||||
self.file_name = self.file_url.split("/files/")[-1]
|
||||
|
||||
if not os.path.exists(get_files_path(self.file_name)):
|
||||
frappe.throw(_("File {0} does not exist").format(self.file_url), IOError)
|
||||
|
||||
def validate_duplicate_entry(self):
|
||||
if not self.flags.ignore_duplicate_entry_error and not self.is_folder:
|
||||
# check duplicate name
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue