Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapcache
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
slapcache
Commits
b07b373b
Commit
b07b373b
authored
Apr 14, 2020
by
Thomas Gambier
🚴🏼
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove temporary files
parent
6fc26a35
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
16 deletions
+22
-16
slapcache/signature.py
slapcache/signature.py
+22
-16
No files found.
slapcache/signature.py
View file @
b07b373b
...
@@ -90,11 +90,11 @@ class NetworkCache:
...
@@ -90,11 +90,11 @@ class NetworkCache:
file_descriptor
=
open
(
path
,
'rb'
)
file_descriptor
=
open
(
path
,
'rb'
)
if
not
(
self
.
dir_url
and
self
.
cache_url
):
if
not
(
self
.
dir_url
and
self
.
cache_url
):
raise
ValueError
(
"upload-dir-url and/or upload-cache-url is not defined"
)
raise
ValueError
(
"upload-dir-url and/or upload-cache-url is not defined"
)
# backward compatibility
# backward compatibility
metadata_dict
.
setdefault
(
'file'
,
'notused'
)
metadata_dict
.
setdefault
(
'file'
,
'notused'
)
metadata_dict
.
setdefault
(
'urlmd5'
,
'notused'
)
metadata_dict
.
setdefault
(
'urlmd5'
,
'notused'
)
# convert '' into None in order to call nc nicely
# convert '' into None in order to call nc nicely
with
NetworkcacheClient
(
self
.
cache_url
,
self
.
dir_url
,
with
NetworkcacheClient
(
self
.
cache_url
,
self
.
dir_url
,
signature_private_key_file
=
self
.
signature_private_key_file
or
None
,
signature_private_key_file
=
self
.
signature_private_key_file
or
None
,
...
@@ -181,7 +181,6 @@ class Signature:
...
@@ -181,7 +181,6 @@ class Signature:
"""
"""
Download a tar of the repository from cache, and untar it.
Download a tar of the repository from cache, and untar it.
"""
"""
info
,
sha256path
=
tempfile
.
mkstemp
()
shacache
=
NetworkCache
(
self
.
config
.
slapos_configuration
)
shacache
=
NetworkCache
(
self
.
config
.
slapos_configuration
)
if
shacache
.
signature_certificate_list
is
None
:
if
shacache
.
signature_certificate_list
is
None
:
...
@@ -193,25 +192,32 @@ class Signature:
...
@@ -193,25 +192,32 @@ class Signature:
if
download_metadata_dict
:
if
download_metadata_dict
:
self
.
log
(
'File downloaded in %s'
,
path
)
self
.
log
(
'File downloaded in %s'
,
path
)
current_sha256
=
self
.
get_file_hash
(
path
)
current_sha256
=
self
.
get_file_hash
(
path
)
if
shacache
.
download
(
path
=
sha256path
,
required_key_list
=
[
'timestamp'
],
with
tempfile
.
NamedTemporaryFile
()
as
f_256
:
strategy
=
strategy
,
is_sha256file
=
True
):
sha256path
=
f_256
.
name
self
.
log
(
'sha 256 downloaded in %s'
,
sha256path
)
if
shacache
.
download
(
path
=
sha256path
,
required_key_list
=
[
'timestamp'
],
with
open
(
sha256path
,
'rb'
)
as
f
:
strategy
=
strategy
,
is_sha256file
=
True
):
expected_sha256
=
f
.
read
()
self
.
log
(
'sha 256 downloaded in %s'
,
sha256path
)
expected_sha256
=
f_256
.
read
()
if
current_sha256
==
expected_sha256
:
return
True
if
current_sha256
==
expected_sha256
:
else
:
return
True
raise
ValueError
(
"%s != %s"
%
(
current_sha256
,
expected_sha256
))
else
:
raise
ValueError
(
"%s != %s"
%
(
current_sha256
,
expected_sha256
))
def
download
(
self
):
def
download
(
self
):
"""
"""
Get status information and return its path
Get status information and return its path
"""
"""
info
,
path
=
tempfile
.
mkstemp
()
info
,
path
=
tempfile
.
mkstemp
()
if
not
self
.
_download
(
path
)
==
False
:
if
self
.
_download
(
path
):
shutil
.
move
(
path
,
self
.
config
.
destination
)
try
:
shutil
.
move
(
path
,
self
.
config
.
destination
)
except
Exception
as
e
:
self
.
log
(
e
)
self
.
log
(
'Fail to move %s to %s, maybe permission problem?'
,
path
,
self
.
config
.
destination
)
os
.
remove
(
path
)
else
:
else
:
os
.
remove
(
path
)
raise
ValueError
(
"No result from shacache"
)
raise
ValueError
(
"No result from shacache"
)
def
_upload
(
self
,
path
):
def
_upload
(
self
,
path
):
...
...
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