Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gelencsér Szabolcs
/
storagedriver
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Wiki
Members
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
A prog2-höz tartozó friss repo anyagok itt elérhetőek:
https://git.iit.bme.hu/
Commit
04b3aede
authored
Nov 12, 2014
by
Guba Sándor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add maximum_size nad DOWNLOAD_MAX_SIZE (env) variable
parent
2d0631fb
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
2 deletions
+7
-2
disk.py
+7
-2
No files found.
disk.py
View file @
04b3aede
...
...
@@ -19,6 +19,8 @@ re_qemu_img = re.compile(r'(file format: (?P<format>(qcow2|raw))|'
r'virtual size: \w+ \((?P<size>[0-9]+) bytes\)|'
r'backing file: \S+ \(actual path: (?P<base>\S+)\))$'
)
maximum_size
=
float
(
os
.
getenv
(
"DOWNLOAD_MAX_SIZE"
,
1024
*
1024
*
1024
*
10
))
class
AbortException
(
Exception
):
pass
...
...
@@ -204,7 +206,7 @@ class Disk(object):
# undocumented zlib feature http://stackoverflow.com/a/2424549
elif
ext
==
'bz2'
:
decompressor
=
BZ2Decompressor
()
clen
=
m
ax
(
int
(
r
.
headers
.
get
(
'content-length'
,
700000000
)),
1
)
clen
=
m
in
(
int
(
r
.
headers
.
get
(
'content-length'
,
maximum_size
)),
1
)
percent
=
0
try
:
with
open
(
disk_path
,
'wb'
)
as
f
:
...
...
@@ -213,6 +215,9 @@ class Disk(object):
chunk
=
decompressor
.
decompress
(
chunk
)
f
.
write
(
chunk
)
actsize
=
f
.
tell
()
if
actsize
>
maximum_size
:
raise
Exception
(
"
%
s file is too big. Maximum size "
"is
%
s"
%
url
,
maximum_size
)
new_percent
=
min
(
100
,
round
(
actsize
*
100.0
/
clen
))
if
new_percent
>
percent
:
percent
=
new_percent
...
...
@@ -309,7 +314,7 @@ class Disk(object):
percent
=
0
diff_disk
=
Disk
.
get
(
self
.
dir
,
self
.
name
)
base_disk
=
Disk
.
get
(
self
.
dir
,
self
.
base_name
)
clen
=
m
ax
(
base_disk
.
actual_size
+
diff_disk
.
actual_size
,
clen
=
m
in
(
base_disk
.
actual_size
+
diff_disk
.
actual_size
,
diff_disk
.
size
)
output
=
new_disk
.
get_path
()
proc
=
subprocess
.
Popen
(
cmdline
)
...
...
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