Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Turris
updater
updater
Commits
5a451dac
Verified
Commit
5a451dac
authored
Jan 26, 2017
by
Karel Koci
🤘
Browse files
Don't fail if there is no journal to recover
parent
77a44a21
Pipeline
#1391
passed with stage
in 7 minutes and 10 seconds
Changes
4
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
src/lib/autoload/a_07_transaction.lua
View file @
5a451dac
--[[
Copyright 2016, CZ.NIC z.s.p.o. (http://www.nic.cz/)
Copyright 2016
-2017
, CZ.NIC z.s.p.o. (http://www.nic.cz/)
This file is part of the turris updater.
...
...
@@ -39,6 +39,7 @@ local utils = require "utils"
local
journal
=
require
"journal"
local
DBG
=
DBG
local
WARN
=
WARN
local
INFO
=
INFO
local
state_dump
=
state_dump
local
sync
=
sync
local
log_event
=
log_event
...
...
@@ -349,6 +350,10 @@ end
function
recover
()
local
run_state
=
backend
.
run_state
()
local
previous
=
journal
.
recover
()
if
not
previous
then
INFO
(
"No journal to recover"
);
return
{}
end
local
status
=
{}
for
_
,
value
in
ipairs
(
previous
)
do
assert
(
not
status
[
value
.
type
])
...
...
src/lib/journal.c
View file @
5a451dac
/*
* Copyright 2016, CZ.NIC z.s.p.o. (http://www.nic.cz/)
* Copyright 2016
-2017
, CZ.NIC z.s.p.o. (http://www.nic.cz/)
*
* This file is part of the turris updater.
*
...
...
@@ -119,7 +119,7 @@ static void journal_write(enum record_type type, size_t num_params, const size_t
ASSERT_MSG
(
!
error
,
"Failed to write journal: %s"
,
strerror
(
errno
));
}
static
void
journal_open
(
lua_State
*
L
,
int
flags
)
{
static
bool
journal_open
(
lua_State
*
L
,
int
flags
)
{
DBG
(
"Opening journal"
);
if
(
fd
!=
-
1
)
luaL_error
(
L
,
"Journal already open"
);
...
...
@@ -133,7 +133,7 @@ static void journal_open(lua_State *L, int flags) {
luaL_error
(
L
,
"Unfinished journal exists"
);
case
ENOENT
:
if
(
!
(
flags
&
O_CREAT
))
luaL_error
(
L
,
"No journal to recover"
)
;
return
false
;
// Otherwise ‒ fall through to the default section
default:
luaL_error
(
L
,
"Error opening journal: %s"
,
strerror
(
errno
));
...
...
@@ -142,6 +142,7 @@ static void journal_open(lua_State *L, int flags) {
ASSERT_MSG
(
fcntl
(
fd
,
F_SETFD
,
(
long
)
FD_CLOEXEC
)
!=
-
1
,
"Failed to set close on exec on journal FD: %s"
,
strerror
(
errno
));
// Keep a copy of the journal path, someone might change it and we want to remove the correct journal on finish
journal_path
=
strdup
(
path
);
return
true
;
}
static
int
lua_fresh
(
lua_State
*
L
)
{
...
...
@@ -255,7 +256,8 @@ FAIL:
}
static
int
lua_recover
(
lua_State
*
L
)
{
journal_open
(
L
,
0
);
if
(
!
journal_open
(
L
,
0
))
return
0
;
lua_newtable
(
L
);
size_t
i
=
0
;
off_t
offset
=
0
;
...
...
src/lib/lua_funcs.txt
View file @
5a451dac
...
...
@@ -190,7 +190,7 @@ There are following functions:
fresh():: Open a new journal. It fails if there's a journal file
already.
recover():: Open a previous journal. It returns table with the
content of the journal. I
t fails in case
there
'
s no journal.
content of the journal. I
f
there
i
s no journal
nil is returned
.
finish([keep]):: Close the journal. If the keep is set to true,
it keeps the journal in place, otherwise it is deleted. The idea
is that the application would close the journal when it succeeds,
...
...
tests/journal.lua
View file @
5a451dac
--[[
Copyright 2016, CZ.NIC z.s.p.o. (http://www.nic.cz/)
Copyright 2016
-2017
, CZ.NIC z.s.p.o. (http://www.nic.cz/)
This file is part of the turris updater.
...
...
@@ -79,7 +79,7 @@ function test_recover_empty()
local
dir
=
dir_init
()
assert_table_equal
({},
ls
(
dir
))
-- Nothing to recover
assert_
error
(
function
()
J
.
recover
()
end
)
assert_
nil
(
J
.
recover
())
J
.
fresh
()
-- Keep the journal file
J
.
finish
(
true
)
...
...
Write
Preview
Supports
Markdown
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