Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
installsystems
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Seblu
installsystems
Commits
16784add
Commit
16784add
authored
13 years ago
by
Sebastien Luttringer
Browse files
Options
Downloads
Patches
Plain Diff
cachify doesn't create empty file when failing to get database
this commit also make cachify more exception safe
parent
0dbc483a
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
installsystems/repository.py
+32
-24
32 additions, 24 deletions
installsystems/repository.py
with
32 additions
and
24 deletions
installsystems/repository.py
+
32
−
24
View file @
16784add
...
...
@@ -84,6 +84,7 @@ class Repository(object):
try
:
self
.
db
=
Database
(
config
.
dbpath
)
except
:
debug
(
"
Unable to load database %s
"
%
config
.
dbpath
)
self
.
config
.
offline
=
True
if
self
.
config
.
offline
:
debug
(
"
Repository %s is offline
"
%
config
.
name
)
...
...
@@ -542,23 +543,23 @@ class RepositoryManager(object):
:param temp: repository db should be stored in a temporary location
:param nosync: if a cache exists, don
'
t try to update it
'''
# if cache is disable => temp =True
if
self
.
cache_path
is
None
:
temp
=
True
try
:
original_dbpath
=
config
.
dbpath
if
temp
and
nosync
:
raise
IOError
(
"
Unable to cache, sync is disabled
"
)
# Ensure destination file exists
if
temp
is
True
or
self
.
cache_path
is
None
:
# this is a forced temporary repository or without name repo
tempfd
,
filedest
=
tempfile
.
mkstemp
()
raise
IOError
(
"
sync is disabled
"
)
elif
temp
:
# this is a temporary cached repository
tempfd
,
config
.
dbpath
=
tempfile
.
mkstemp
()
os
.
close
(
tempfd
)
self
.
tempfiles
.
append
(
filedest
)
self
.
tempfiles
.
append
(
config
.
dbpath
)
else
:
filedest
=
os
.
path
.
join
(
self
.
cache_path
,
config
.
name
)
# create file if not exists
if
not
os
.
path
.
exists
(
filedest
):
open
(
filedest
,
"
wb
"
)
config
.
dbpath
=
os
.
path
.
join
(
self
.
cache_path
,
config
.
name
)
if
not
nosync
:
# Open remote database
rdb
=
PipeFile
(
config
.
dbpath
,
timeout
=
self
.
timeout
)
rdb
=
PipeFile
(
original_
dbpath
,
timeout
=
self
.
timeout
)
# get remote last modification
if
rdb
.
mtime
is
None
:
# We doesn't have modification time, we use the last file
...
...
@@ -570,21 +571,28 @@ class RepositoryManager(object):
else
:
rlast
=
rdb
.
mtime
# get local last value
llast
=
int
(
os
.
stat
(
filedest
).
st_mtime
)
if
os
.
path
.
exists
(
config
.
dbpath
):
llast
=
int
(
os
.
stat
(
config
.
dbpath
).
st_mtime
)
else
:
llast
=
-
2
# if repo is out of date, download it
if
rlast
!=
llast
:
arrow
(
"
Downloading %s
"
%
config
.
dbpath
)
rdb
.
progressbar
=
True
ldb
=
open
(
filedest
,
"
wb
"
)
rdb
.
consume
(
ldb
)
ldb
.
close
()
rdb
.
close
()
istools
.
chrights
(
filedest
,
uid
=
config
.
uid
,
gid
=
config
.
gid
,
mode
=
config
.
fmod
,
mtime
=
rlast
)
config
.
dbpath
=
filedest
try
:
arrow
(
"
Downloading %s
"
%
original_dbpath
)
rdb
.
progressbar
=
True
ldb
=
open
(
config
.
dbpath
,
"
wb
"
)
rdb
.
consume
(
ldb
)
ldb
.
close
()
rdb
.
close
()
istools
.
chrights
(
config
.
dbpath
,
uid
=
config
.
uid
,
gid
=
config
.
gid
,
mode
=
config
.
fmod
,
mtime
=
rlast
)
except
:
if
os
.
path
.
exists
(
config
.
dbpath
):
os
.
unlink
(
config
.
dbpath
)
raise
except
IOError
as
e
:
# if something append bad during caching, we mark repo as offline
debug
(
"
Unable to cache repository %s: %s
"
%
(
config
.
name
,
e
))
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment