LCOV - code coverage report
Current view: top level - glib/gio - gio-tool-mkdir.c (source / functions) Hit Total Coverage
Test: unnamed Lines: 0 40 0.0 %
Date: 2024-04-23 05:16:05 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 parent = FALSE;
      31                 :            : 
      32                 :            : static const GOptionEntry entries[] = {
      33                 :            :   { "parent", 'p', 0, G_OPTION_ARG_NONE, &parent, N_("Create parent directories"), NULL },
      34                 :            :   G_OPTION_ENTRY_NULL
      35                 :            : };
      36                 :            : 
      37                 :            : int
      38                 :          0 : handle_mkdir (int argc, char *argv[], gboolean do_help)
      39                 :            : {
      40                 :            :   GOptionContext *context;
      41                 :            :   gchar *param;
      42                 :          0 :   GError *error = NULL;
      43                 :            :   GFile *file;
      44                 :          0 :   int retval = 0;
      45                 :            :   int i;
      46                 :            : 
      47                 :          0 :   g_set_prgname ("gio mkdir");
      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, _("Create directories."));
      55                 :          0 :   g_option_context_set_description (context,
      56                 :          0 :       _("gio mkdir is similar to the traditional mkdir utility, but using GIO\n"
      57                 :            :         "locations instead of local files: for example, you can use something\n"
      58                 :            :         "like smb://server/resource/mydir as location."));
      59                 :          0 :   g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
      60                 :            : 
      61         [ #  # ]:          0 :   if (do_help)
      62                 :            :     {
      63                 :          0 :       show_help (context, NULL);
      64                 :          0 :       g_option_context_free (context);
      65                 :          0 :       return 0;
      66                 :            :     }
      67                 :            : 
      68         [ #  # ]:          0 :   if (!g_option_context_parse (context, &argc, &argv, &error))
      69                 :            :     {
      70                 :          0 :       show_help (context, error->message);
      71                 :          0 :       g_error_free (error);
      72                 :          0 :       g_option_context_free (context);
      73                 :          0 :       return 1;
      74                 :            :     }
      75                 :            : 
      76         [ #  # ]:          0 :   if (argc < 2)
      77                 :            :     {
      78                 :          0 :       show_help (context, _("No locations given"));
      79                 :          0 :       g_option_context_free (context);
      80                 :          0 :       return 1;
      81                 :            :     }
      82                 :            : 
      83                 :          0 :   g_option_context_free (context);
      84                 :            : 
      85         [ #  # ]:          0 :   for (i = 1; i < argc; i++)
      86                 :            :     {
      87                 :          0 :       file = g_file_new_for_commandline_arg (argv[i]);
      88                 :          0 :       error = NULL;
      89         [ #  # ]:          0 :       if (parent)
      90                 :            :         {
      91         [ #  # ]:          0 :           if (!g_file_make_directory_with_parents (file, NULL, &error))
      92                 :            :             {
      93                 :          0 :               print_file_error (file, error->message);
      94                 :          0 :               g_error_free (error);
      95                 :          0 :               retval = 1;
      96                 :            :             }
      97                 :            :         }
      98                 :            :       else
      99                 :            :         {
     100         [ #  # ]:          0 :           if (!g_file_make_directory (file, NULL, &error))
     101                 :            :             {
     102                 :          0 :               print_file_error (file, error->message);
     103                 :          0 :               g_error_free (error);
     104                 :          0 :               retval = 1;
     105                 :            :             }
     106                 :          0 :           g_object_unref (file);
     107                 :            :         }
     108                 :            :     }
     109                 :            : 
     110                 :          0 :   return retval;
     111                 :            : 
     112                 :            : }

Generated by: LCOV version 1.14