mirror of
https://github.com/flatpak/flatpak.git
synced 2026-06-30 19:26:47 -04:00
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:
committed by
Alexander Larsson
parent
5ba3b47d64
commit
390243fb7c
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user