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
pwmt
zathura
Commits
ae97de3a
Commit
ae97de3a
authored
Apr 30, 2017
by
Sebastian Ramacher
Browse files
Check basepath in database backend
Signed-off-by:
Sebastian Ramacher
<
sebastian+dev@ramacher.at
>
parent
1317675c
Changes
5
Hide whitespace changes
Inline
Side-by-side
zathura/completion.c
View file @
ae97de3a
...
...
@@ -191,18 +191,15 @@ list_files_for_cc(zathura_t* zathura, const char* input, bool check_file_ext, in
}
if
(
show_recent
>
0
&&
zathura
->
database
!=
NULL
)
{
girara_list_t
*
recent_files
=
zathura_db_get_recent_files
(
zathura
->
database
,
show_recent
);
girara_list_t
*
recent_files
=
zathura_db_get_recent_files
(
zathura
->
database
,
show_recent
,
path
);
if
(
recent_files
==
NULL
)
{
goto
error_free
;
}
if
(
girara_list_size
(
recent_files
)
!=
0
)
{
const
size_t
path_len
=
strlen
(
path
);
GIRARA_LIST_FOREACH
(
recent_files
,
const
char
*
,
iter
,
file
)
if
(
strncmp
(
path
,
file
,
path_len
)
==
0
)
{
girara_debug
(
"adding %s (recent file)"
,
file
);
girara_completion_group_add_element
(
history_group
,
file
,
NULL
);
}
girara_debug
(
"adding %s (recent file)"
,
file
);
girara_completion_group_add_element
(
history_group
,
file
,
NULL
);
GIRARA_LIST_FOREACH_END
(
recent_files
,
const
char
*
,
iter
,
file
);
girara_list_free
(
recent_files
);
}
else
{
...
...
zathura/database-plain.c
View file @
ae97de3a
...
...
@@ -63,7 +63,7 @@ static bool plain_get_fileinfo(zathura_database_t* db, const char* fil
static
void
plain_set_property
(
GObject
*
object
,
guint
prop_id
,
const
GValue
*
value
,
GParamSpec
*
pspec
);
static
void
plain_io_append
(
GiraraInputHistoryIO
*
db
,
const
char
*
);
static
girara_list_t
*
plain_io_read
(
GiraraInputHistoryIO
*
db
);
static
girara_list_t
*
plain_get_recent_files
(
zathura_database_t
*
db
,
int
max
);
static
girara_list_t
*
plain_get_recent_files
(
zathura_database_t
*
db
,
int
max
,
const
char
*
basepath
);
/* forward declaration */
static
bool
zathura_db_check_file
(
const
char
*
path
);
...
...
@@ -852,7 +852,7 @@ compare_time(const void* l, const void* r, void* data)
}
static
girara_list_t
*
plain_get_recent_files
(
zathura_database_t
*
db
,
int
max
)
plain_get_recent_files
(
zathura_database_t
*
db
,
int
max
,
const
char
*
basepath
)
{
zathura_plaindatabase_private_t
*
priv
=
ZATHURA_PLAINDATABASE_GET_PRIVATE
(
db
);
...
...
@@ -868,12 +868,15 @@ plain_get_recent_files(zathura_database_t* db, int max)
g_qsort_with_data
(
groups
,
groups_size
,
sizeof
(
gchar
*
),
compare_time
,
priv
->
history
);
}
if
(
max
>=
0
&&
(
gsize
)
max
<
groups_size
)
{
groups_size
=
max
;
}
const
size_t
basepath_len
=
basepath
!=
NULL
?
strlen
(
basepath
)
:
0
;
for
(
gsize
s
=
0
;
s
!=
groups_size
&&
max
!=
0
;
++
s
)
{
if
(
basepath
!=
NULL
&&
strncmp
(
groups
[
s
],
basepath
,
basepath_len
)
!=
0
)
{
continue
;
}
for
(
gsize
s
=
0
;
s
!=
groups_size
;
++
s
)
{
girara_list_append
(
result
,
g_strdup
(
groups
[
s
]));
--
max
;
}
g_strfreev
(
groups
);
...
...
zathura/database-sqlite.c
View file @
ae97de3a
...
...
@@ -30,7 +30,7 @@ static bool sqlite_get_fileinfo(zathura_database_t* db, const char* fi
static
void
sqlite_set_property
(
GObject
*
object
,
guint
prop_id
,
const
GValue
*
value
,
GParamSpec
*
pspec
);
static
void
sqlite_io_append
(
GiraraInputHistoryIO
*
db
,
const
char
*
);
static
girara_list_t
*
sqlite_io_read
(
GiraraInputHistoryIO
*
db
);
static
girara_list_t
*
sqlite_get_recent_files
(
zathura_database_t
*
db
,
int
max
);
static
girara_list_t
*
sqlite_get_recent_files
(
zathura_database_t
*
db
,
int
max
,
const
char
*
basepath
);
typedef
struct
zathura_sqldatabase_private_s
{
sqlite3
*
session
;
...
...
@@ -761,13 +761,15 @@ sqlite_io_read(GiraraInputHistoryIO* db)
}
static
girara_list_t
*
sqlite_get_recent_files
(
zathura_database_t
*
db
,
int
max
)
sqlite_get_recent_files
(
zathura_database_t
*
db
,
int
max
,
const
char
*
basepath
)
{
static
const
char
SQL_HISTORY_GET
[]
=
"SELECT file FROM fileinfo ORDER BY time DESC LIMIT ?"
;
static
const
char
SQL_HISTORY_GET_WITH_BASEPATH
[]
=
"SELECT file FROM fileinfo WHERE file LIKE '?%' ORDER BY time DESC LIMIT ?"
;
zathura_sqldatabase_private_t
*
priv
=
ZATHURA_SQLDATABASE_GET_PRIVATE
(
db
);
sqlite3_stmt
*
stmt
=
prepare_statement
(
priv
->
session
,
SQL_HISTORY_GET
);
sqlite3_stmt
*
stmt
=
prepare_statement
(
priv
->
session
,
basepath
==
NULL
?
SQL_HISTORY_GET
:
SQL_HISTORY_GET_WITH_BASEPATH
);
if
(
stmt
==
NULL
)
{
return
NULL
;
}
...
...
@@ -776,7 +778,8 @@ sqlite_get_recent_files(zathura_database_t* db, int max)
max
=
INT_MAX
;
}
if
(
sqlite3_bind_int
(
stmt
,
1
,
max
)
!=
SQLITE_OK
)
{
if
(
sqlite3_bind_int
(
stmt
,
1
,
max
)
!=
SQLITE_OK
&&
(
basepath
==
NULL
||
sqlite3_bind_text
(
stmt
,
2
,
basepath
,
-
1
,
NULL
)
!=
SQLITE_OK
))
{
sqlite3_finalize
(
stmt
);
girara_error
(
"Failed to bind arguments."
);
return
false
;
...
...
zathura/database.c
View file @
ae97de3a
...
...
@@ -70,9 +70,9 @@ zathura_db_get_fileinfo(zathura_database_t* db, const char* file,
}
girara_list_t
*
zathura_db_get_recent_files
(
zathura_database_t
*
db
,
int
max
)
zathura_db_get_recent_files
(
zathura_database_t
*
db
,
int
max
,
const
char
*
basepath
)
{
g_return_val_if_fail
(
ZATHURA_IS_DATABASE
(
db
),
NULL
);
return
ZATHURA_DATABASE_GET_INTERFACE
(
db
)
->
get_recent_files
(
db
,
max
);
return
ZATHURA_DATABASE_GET_INTERFACE
(
db
)
->
get_recent_files
(
db
,
max
,
basepath
);
}
zathura/database.h
View file @
ae97de3a
...
...
@@ -51,7 +51,7 @@ struct _ZathuraDatabaseInterface
bool
(
*
get_fileinfo
)(
ZathuraDatabase
*
db
,
const
char
*
file
,
zathura_fileinfo_t
*
file_info
);
girara_list_t
*
(
*
get_recent_files
)(
ZathuraDatabase
*
db
,
int
max
);
girara_list_t
*
(
*
get_recent_files
)(
ZathuraDatabase
*
db
,
int
max
,
const
char
*
basepath
);
};
GType
zathura_database_get_type
(
void
)
G_GNUC_CONST
;
...
...
@@ -138,7 +138,7 @@ bool zathura_db_get_fileinfo(zathura_database_t* db, const char* file,
* limit is applied.
* @return list of files
*/
girara_list_t
*
zathura_db_get_recent_files
(
zathura_database_t
*
db
,
int
max
);
girara_list_t
*
zathura_db_get_recent_files
(
zathura_database_t
*
db
,
int
max
,
const
char
*
basepath
);
#endif // DATABASE_H
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