utils: Add flatpak_file_is_non_empty()

Utility to check for existing, regular (or symlink to regular) files
that are not empty.wq
This commit is contained in:
Alexander Larsson
2018-09-17 14:54:22 +01:00
committed by Alexander Larsson
parent 5ba3b47d64
commit 390243fb7c
2 changed files with 17 additions and 0 deletions

View File

@@ -493,6 +493,8 @@ char * flatpak_resolve_link (const char *path,
GError **error);
char * flatpak_canonicalize_filename (const char *path);
gboolean flatpak_file_is_non_empty (const char *path);
gboolean flatpak_file_rename (GFile *from,
GFile *to,
GCancellable *cancellable,

View File

@@ -2164,6 +2164,21 @@ flatpak_canonicalize_filename (const char *path)
return g_file_get_path (file);
}
/* Check for non-empty regular files */
gboolean
flatpak_file_is_non_empty (const char *path)
{
struct stat stbuf;
if (TEMP_FAILURE_RETRY (stat (path, &stbuf)) != 0)
return FALSE;
if (!S_ISREG (stbuf.st_mode) || stbuf.st_size == 0)
return FALSE;
return TRUE;
}
gboolean
flatpak_file_rename (GFile *from,
GFile *to,