Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
snf-ganeti
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
itminedu
snf-ganeti
Commits
081b1e69
Commit
081b1e69
authored
17 years ago
by
Michael Hanselmann
Browse files
Options
Downloads
Patches
Plain Diff
Prevent race condition in CreateBackup().
Reviewed-by: ultrotter
parent
283f9d4c
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
lib/utils.py
+14
-4
14 additions, 4 deletions
lib/utils.py
with
14 additions
and
4 deletions
lib/utils.py
+
14
−
4
View file @
081b1e69
...
...
@@ -748,10 +748,20 @@ def CreateBackup(file_name):
raise
errors
.
ProgrammerError
(
"
Can
'
t make a backup of a non-file
'
%s
'"
%
file_name
)
# Warning: the following code contains a race condition when we create more
# than one backup of the same file in a second.
backup_name
=
file_name
+
'
.backup-%d
'
%
int
(
time
.
time
())
shutil
.
copyfile
(
file_name
,
backup_name
)
prefix
=
'
%s.backup-%d.
'
%
(
os
.
path
.
basename
(
file_name
),
int
(
time
.
time
()))
dir
=
os
.
path
.
dirname
(
file_name
)
fsrc
=
open
(
file_name
,
'
rb
'
)
try
:
(
fd
,
backup_name
)
=
tempfile
.
mkstemp
(
prefix
=
prefix
,
dir
=
dir
)
fdst
=
os
.
fdopen
(
fd
,
'
wb
'
)
try
:
shutil
.
copyfileobj
(
fsrc
,
fdst
)
finally
:
fdst
.
close
()
finally
:
fsrc
.
close
()
return
backup_name
...
...
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