LCOV - code coverage report
Current view: top level - glib/gio - gio-tool-remove.c (source / functions) Hit Total Coverage
Test: unnamed Lines: 0 34 0.0 %
Date: 2024-04-16 05:15:53 Functions: 0 1 0.0 %
Branches: 0 14 0.0 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * Copyright 2015 Red Hat, Inc.
       3                 :            :  *
       4                 :            :  * SPDX-License-Identifier: LGPL-2.1-or-later
       5                 :            :  *
       6                 :            :  * This library is free software; you can redistribute it and/or
       7                 :            :  * modify it under the terms of the GNU Lesser General Public
       8                 :            :  * License as published by the Free Software Foundation; either
       9                 :            :  * version 2.1 of the License, or (at your option) any later version.
      10                 :            :  *
      11                 :            :  * This library is distributed in the hope that it will be useful,
      12                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      13                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      14                 :            :  * Lesser General Public License for more details.
      15                 :            :  *
      16                 :            :  * You should have received a copy of the GNU Lesser General Public
      17                 :            :  * License along with this library; if not, see <http://www.gnu.org/licenses/>.
      18                 :            :  *
      19                 :            :  * Author: Matthias Clasen <mclasen@redhat.com>
      20                 :            :  */
      21                 :            : 
      22                 :            : #include "config.h"
      23                 :            : 
      24                 :            : #include <gio/gio.h>
      25                 :            : #include <gi18n.h>
      26                 :            : 
      27                 :            : #include "gio-tool.h"
      28                 :            : 
      29                 :            : 
      30                 :            : static gboolean force = FALSE;
      31                 :            : 
      32                 :            : static const GOptionEntry entries[] = {
      33                 :            :   {"force", 'f', 0, G_OPTION_ARG_NONE, &force, N_("Ignore nonexistent files, never prompt"), NULL},
      34                 :            :   G_OPTION_ENTRY_NULL
      35                 :            : };
      36                 :            : 
      37                 :            : int
      38                 :          0 : handle_remove (int argc, char *argv[], gboolean do_help)
      39                 :            : {
      40                 :            :   GOptionContext *context;
      41                 :            :   gchar *param;
      42                 :          0 :   GError *error = NULL;
      43                 :            :   GFile *file;
      44                 :            :   int retval;
      45                 :            :   int i;
      46                 :            : 
      47                 :          0 :   g_set_prgname ("gio remove");
      48                 :            : 
      49                 :            :   /* Translators: commandline placeholder */
      50                 :          0 :   param = g_strdup_printf ("%s…", _("LOCATION"));
      51                 :          0 :   context = g_option_context_new (param);
      52                 :          0 :   g_free (param);
      53                 :          0 :   g_option_context_set_help_enabled (context, FALSE);
      54                 :          0 :   g_option_context_set_summary (context, _("Delete the given files."));
      55                 :          0 :   g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
      56                 :            : 
      57         [ #  # ]:          0 :   if (do_help)
      58                 :            :     {
      59                 :          0 :       show_help (context, NULL);
      60                 :          0 :       g_option_context_free (context);
      61                 :          0 :       return 0;
      62                 :            :     }
      63                 :            : 
      64         [ #  # ]:          0 :   if (!g_option_context_parse (context, &argc, &argv, &error))
      65                 :            :     {
      66                 :          0 :       show_help (context, error->message);
      67                 :          0 :       g_error_free (error);
      68                 :          0 :       g_option_context_free (context);
      69                 :          0 :       return 1;
      70                 :            :     }
      71                 :            : 
      72         [ #  # ]:          0 :   if (argc == 1)
      73                 :            :     {
      74                 :          0 :       show_help (context, _("No locations given"));
      75                 :          0 :       g_option_context_free (context);
      76                 :          0 :       return 1;
      77                 :            :     }
      78                 :            : 
      79                 :          0 :   g_option_context_free (context);
      80                 :            : 
      81                 :          0 :   retval = 0;
      82         [ #  # ]:          0 :   for (i = 1; i < argc; i++)
      83                 :            :     {
      84                 :          0 :       file = g_file_new_for_commandline_arg (argv[i]);
      85         [ #  # ]:          0 :       if (!g_file_delete (file, NULL, &error))
      86                 :            :         {
      87   [ #  #  #  # ]:          0 :           if (!force ||
      88                 :          0 :               !g_error_matches (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND))
      89                 :            :             {
      90                 :          0 :               print_file_error (file, error->message);
      91                 :          0 :               retval = 1;
      92                 :            :             }
      93                 :          0 :           g_clear_error (&error);
      94                 :            :         }
      95                 :          0 :       g_object_unref (file);
      96                 :            :     }
      97                 :            : 
      98                 :          0 :   return retval;
      99                 :            : }

Generated by: LCOV version 1.14