Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
D
douban-api-proxy
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
captainwong
douban-api-proxy
Commits
e0faad1e
Commit
e0faad1e
authored
Dec 08, 2019
by
Ozzieisaacs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Handle no write permission to tmp folder (#1060)
parent
fda0ab1e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
14 deletions
+20
-14
editbooks.py
cps/editbooks.py
+16
-6
uploader.py
cps/uploader.py
+1
-1
worker.py
cps/worker.py
+3
-7
No files found.
cps/editbooks.py
View file @
e0faad1e
...
@@ -550,13 +550,19 @@ def upload():
...
@@ -550,13 +550,19 @@ def upload():
flash
(
flash
(
_
(
"File extension '
%(ext)
s' is not allowed to be uploaded to this server"
,
_
(
"File extension '
%(ext)
s' is not allowed to be uploaded to this server"
,
ext
=
file_ext
),
category
=
"error"
)
ext
=
file_ext
),
category
=
"error"
)
return
redirect
(
url_for
(
'web.index'
)
)
return
Response
(
json
.
dumps
({
"location"
:
url_for
(
"web.index"
)}),
mimetype
=
'application/json'
)
else
:
else
:
flash
(
_
(
'File to be uploaded must have an extension'
),
category
=
"error"
)
flash
(
_
(
'File to be uploaded must have an extension'
),
category
=
"error"
)
return
redirect
(
url_for
(
'web.index'
)
)
return
Response
(
json
.
dumps
({
"location"
:
url_for
(
"web.index"
)}),
mimetype
=
'application/json'
)
# extract metadata from file
# extract metadata from file
meta
=
uploader
.
upload
(
requested_file
)
try
:
meta
=
uploader
.
upload
(
requested_file
)
except
(
IOError
,
OSError
):
log
.
error
(
"File
%
s could not saved to temp dir"
,
requested_file
.
filename
)
flash
(
_
(
u"File
%(filename)
s could not saved to temp dir"
,
filename
=
requested_file
.
filename
),
category
=
"error"
)
return
Response
(
json
.
dumps
({
"location"
:
url_for
(
"web.index"
)}),
mimetype
=
'application/json'
)
title
=
meta
.
title
title
=
meta
.
title
authr
=
meta
.
author
authr
=
meta
.
author
tags
=
meta
.
tags
tags
=
meta
.
tags
...
@@ -570,7 +576,8 @@ def upload():
...
@@ -570,7 +576,8 @@ def upload():
if
title
!=
u'Unknown'
and
authr
!=
u'Unknown'
:
if
title
!=
u'Unknown'
and
authr
!=
u'Unknown'
:
entry
=
helper
.
check_exists_book
(
authr
,
title
)
entry
=
helper
.
check_exists_book
(
authr
,
title
)
if
entry
:
if
entry
:
book_html
=
flash
(
_
(
u"Uploaded book probably exists in the library, consider to change before upload new: "
)
log
.
info
(
"Uploaded book probably exists in library"
)
flash
(
_
(
u"Uploaded book probably exists in the library, consider to change before upload new: "
)
+
Markup
(
render_title_template
(
'book_exists_flash.html'
,
entry
=
entry
)),
category
=
"warning"
)
+
Markup
(
render_title_template
(
'book_exists_flash.html'
,
entry
=
entry
)),
category
=
"warning"
)
# check if file path exists, otherwise create it, copy file to calibre path and delete temp file
# check if file path exists, otherwise create it, copy file to calibre path and delete temp file
...
@@ -578,16 +585,19 @@ def upload():
...
@@ -578,16 +585,19 @@ def upload():
try
:
try
:
os
.
makedirs
(
filepath
)
os
.
makedirs
(
filepath
)
except
OSError
:
except
OSError
:
log
.
error
(
"Failed to create path
%
s (Permission denied)"
,
filepath
)
flash
(
_
(
u"Failed to create path
%(path)
s (Permission denied)."
,
path
=
filepath
),
category
=
"error"
)
flash
(
_
(
u"Failed to create path
%(path)
s (Permission denied)."
,
path
=
filepath
),
category
=
"error"
)
return
redirect
(
url_for
(
'web.index'
)
)
return
Response
(
json
.
dumps
({
"location"
:
url_for
(
"web.index"
)}),
mimetype
=
'application/json'
)
try
:
try
:
copyfile
(
meta
.
file_path
,
saved_filename
)
copyfile
(
meta
.
file_path
,
saved_filename
)
except
OSError
:
except
OSError
:
log
.
error
(
"Failed to store file
%
s (Permission denied)"
,
saved_filename
)
flash
(
_
(
u"Failed to store file
%(file)
s (Permission denied)."
,
file
=
saved_filename
),
category
=
"error"
)
flash
(
_
(
u"Failed to store file
%(file)
s (Permission denied)."
,
file
=
saved_filename
),
category
=
"error"
)
return
redirect
(
url_for
(
'web.index'
)
)
return
Response
(
json
.
dumps
({
"location"
:
url_for
(
"web.index"
)}),
mimetype
=
'application/json'
)
try
:
try
:
os
.
unlink
(
meta
.
file_path
)
os
.
unlink
(
meta
.
file_path
)
except
OSError
:
except
OSError
:
log
.
error
(
"Failed to delete file
%(file)
s (Permission denied)"
,
meta
.
file_path
)
flash
(
_
(
u"Failed to delete file
%(file)
s (Permission denied)."
,
file
=
meta
.
file_path
),
flash
(
_
(
u"Failed to delete file
%(file)
s (Permission denied)."
,
file
=
meta
.
file_path
),
category
=
"warning"
)
category
=
"warning"
)
...
...
cps/uploader.py
View file @
e0faad1e
...
@@ -195,12 +195,12 @@ def upload(uploadfile):
...
@@ -195,12 +195,12 @@ def upload(uploadfile):
if
not
os
.
path
.
isdir
(
tmp_dir
):
if
not
os
.
path
.
isdir
(
tmp_dir
):
os
.
mkdir
(
tmp_dir
)
os
.
mkdir
(
tmp_dir
)
filename
=
uploadfile
.
filename
filename
=
uploadfile
.
filename
filename_root
,
file_extension
=
os
.
path
.
splitext
(
filename
)
filename_root
,
file_extension
=
os
.
path
.
splitext
(
filename
)
md5
=
hashlib
.
md5
()
md5
=
hashlib
.
md5
()
md5
.
update
(
filename
.
encode
(
'utf-8'
))
md5
.
update
(
filename
.
encode
(
'utf-8'
))
tmp_file_path
=
os
.
path
.
join
(
tmp_dir
,
md5
.
hexdigest
())
tmp_file_path
=
os
.
path
.
join
(
tmp_dir
,
md5
.
hexdigest
())
log
.
debug
(
"Temporary file:
%
s"
,
tmp_file_path
)
uploadfile
.
save
(
tmp_file_path
)
uploadfile
.
save
(
tmp_file_path
)
meta
=
process
(
tmp_file_path
,
filename_root
,
file_extension
)
meta
=
process
(
tmp_file_path
,
filename_root
,
file_extension
)
return
meta
return
meta
cps/worker.py
View file @
e0faad1e
...
@@ -437,19 +437,15 @@ class WorkerThread(threading.Thread):
...
@@ -437,19 +437,15 @@ class WorkerThread(threading.Thread):
if
self
.
last
>=
20
:
if
self
.
last
>=
20
:
self
.
_delete_completed_tasks
()
self
.
_delete_completed_tasks
()
# progress=100%, runtime=0, and status finished
# progress=100%, runtime=0, and status finished
log
.
info
(
"Last "
+
str
(
self
.
last
))
log
.
debug
(
"Last "
+
str
(
self
.
last
))
log
.
info
(
"Current "
+
str
(
self
.
current
))
log
.
debug
(
"Current "
+
str
(
self
.
current
))
log
.
info
(
"id"
+
str
(
self
.
id
))
log
.
debug
(
"id"
+
str
(
self
.
id
))
for
i
in
range
(
0
,
len
(
self
.
queue
)):
message
=
'
%
s:
%
s'
%
(
i
,
self
.
queue
[
i
]
.
items
())
log
.
info
(
message
)
self
.
id
+=
1
self
.
id
+=
1
starttime
=
datetime
.
now
()
starttime
=
datetime
.
now
()
self
.
queue
.
append
({
'starttime'
:
starttime
,
'taskType'
:
TASK_UPLOAD
})
self
.
queue
.
append
({
'starttime'
:
starttime
,
'taskType'
:
TASK_UPLOAD
})
self
.
UIqueue
.
append
({
'user'
:
user_name
,
'formStarttime'
:
starttime
,
'progress'
:
"100
%
"
,
'taskMess'
:
taskMessage
,
self
.
UIqueue
.
append
({
'user'
:
user_name
,
'formStarttime'
:
starttime
,
'progress'
:
"100
%
"
,
'taskMess'
:
taskMessage
,
'runtime'
:
'0 s'
,
'stat'
:
STAT_FINISH_SUCCESS
,
'id'
:
self
.
id
,
'taskType'
:
TASK_UPLOAD
})
'runtime'
:
'0 s'
,
'stat'
:
STAT_FINISH_SUCCESS
,
'id'
:
self
.
id
,
'taskType'
:
TASK_UPLOAD
})
# self.UIqueue[self.current]['formStarttime'] = self.queue[self.current]['starttime']
self
.
last
=
len
(
self
.
queue
)
self
.
last
=
len
(
self
.
queue
)
self
.
doLock
.
release
()
self
.
doLock
.
release
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment