mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-07 18:20:22 +01:00
glib-aux: add nm_key_file_db_prune_tmp_files() helper
(cherry picked from commit 3c0f1eb0fd)
This commit is contained in:
parent
567499cddd
commit
4b942e9519
2 changed files with 42 additions and 0 deletions
|
|
@ -385,6 +385,46 @@ nm_key_file_db_to_file(NMKeyFileDB *self, gboolean force)
|
|||
|
||||
/*****************************************************************************/
|
||||
|
||||
void
|
||||
nm_key_file_db_prune_tmp_files(NMKeyFileDB *self)
|
||||
{
|
||||
gs_free char * n_file = NULL;
|
||||
gs_free char * n_dir = NULL;
|
||||
gs_strfreev char **tmpfiles = NULL;
|
||||
gsize i;
|
||||
|
||||
n_file = g_path_get_basename(self->filename);
|
||||
n_dir = g_path_get_dirname(self->filename);
|
||||
|
||||
tmpfiles = nm_utils_find_mkstemp_files(n_dir, n_file);
|
||||
if (!tmpfiles)
|
||||
return;
|
||||
|
||||
for (i = 0; tmpfiles[i]; i++) {
|
||||
const char * tmpfile = tmpfiles[i];
|
||||
gs_free char *full_file = NULL;
|
||||
int r;
|
||||
|
||||
full_file = g_strdup_printf("%s/%s", n_dir, tmpfile);
|
||||
|
||||
r = unlink(full_file);
|
||||
if (r != 0) {
|
||||
int errsv = errno;
|
||||
|
||||
if (errsv != ENOENT) {
|
||||
_LOGD("prune left over temp file %s failed: %s",
|
||||
full_file,
|
||||
nm_strerror_native(errsv));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
_LOGD("prune left over temp file %s", full_file);
|
||||
}
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
void
|
||||
nm_key_file_db_prune(NMKeyFileDB *self,
|
||||
gboolean (*predicate)(const char *key, gpointer user_data),
|
||||
|
|
|
|||
|
|
@ -50,6 +50,8 @@ void nm_key_file_db_set_string_list(NMKeyFileDB * self,
|
|||
|
||||
void nm_key_file_db_to_file(NMKeyFileDB *self, gboolean force);
|
||||
|
||||
void nm_key_file_db_prune_tmp_files(NMKeyFileDB *self);
|
||||
|
||||
void nm_key_file_db_prune(NMKeyFileDB *self,
|
||||
gboolean (*predicate)(const char *key, gpointer user_data),
|
||||
gpointer user_data);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue