root/src/filemanager/filenot.c

/* [previous][next][first][last][top][bottom][index][help]  */

DEFINITIONS

This source file includes following definitions.
  1. my_mkdir_rec
  2. my_mkdir
  3. my_rmdir

   1 /*
   2    Wrapper for routines to notify the
   3    tree about the changes made to the directory
   4    structure.
   5 
   6    Copyright (C) 2011-2025
   7    Free Software Foundation, Inc.
   8 
   9    Author:
  10    Janne Kukonlehto
  11    Miguel de Icaza
  12    Slava Zanko <slavazanko@gmail.com>, 2013
  13 
  14    This file is part of the Midnight Commander.
  15 
  16    The Midnight Commander is free software: you can redistribute it
  17    and/or modify it under the terms of the GNU General Public License as
  18    published by the Free Software Foundation, either version 3 of the License,
  19    or (at your option) any later version.
  20 
  21    The Midnight Commander is distributed in the hope that it will be useful,
  22    but WITHOUT ANY WARRANTY; without even the implied warranty of
  23    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  24    GNU General Public License for more details.
  25 
  26    You should have received a copy of the GNU General Public License
  27    along with this program.  If not, see <https://www.gnu.org/licenses/>.
  28  */
  29 
  30 /** \file  filenot.c
  31  *  \brief Source: wrapper for routines to notify the
  32  *  tree about the changes made to the directory
  33  *  structure.
  34  */
  35 
  36 #include <config.h>
  37 
  38 #include <errno.h>
  39 #include <string.h>
  40 
  41 #include "lib/global.h"
  42 #include "lib/fs.h"
  43 #include "lib/util.h"
  44 #include "lib/vfs/vfs.h"
  45 
  46 #include "filenot.h"
  47 
  48 /*** global variables ****************************************************************************/
  49 
  50 /*** file scope macro definitions ****************************************************************/
  51 
  52 /*** file scope type declarations ****************************************************************/
  53 
  54 /*** forward declarations (file scope functions) *************************************************/
  55 
  56 /*** file scope variables ************************************************************************/
  57 
  58 /* --------------------------------------------------------------------------------------------- */
  59 /*** file scope functions ************************************************************************/
  60 /* --------------------------------------------------------------------------------------------- */
  61 
  62 static int
  63 my_mkdir_rec (const vfs_path_t *vpath, mode_t mode)
     /* [previous][next][first][last][top][bottom][index][help]  */
  64 {
  65     vfs_path_t *q;
  66     int result;
  67 
  68     if (mc_mkdir (vpath, mode) == 0)
  69         return 0;
  70     if (errno != ENOENT)
  71         return (-1);
  72 
  73     // FIXME: should check instead if vpath is at the root of that filesystem
  74     if (!vfs_file_is_local (vpath))
  75         return (-1);
  76 
  77     if (strcmp (vfs_path_as_str (vpath), PATH_SEP_STR) == 0)
  78     {
  79         errno = ENOTDIR;
  80         return (-1);
  81     }
  82 
  83     q = vfs_path_append_new (vpath, "..", (char *) NULL);
  84     result = my_mkdir_rec (q, mode);
  85     vfs_path_free (q, TRUE);
  86 
  87     if (result == 0)
  88         result = mc_mkdir (vpath, mode);
  89 
  90     return result;
  91 }
  92 
  93 /* --------------------------------------------------------------------------------------------- */
  94 /*** public functions ****************************************************************************/
  95 /* --------------------------------------------------------------------------------------------- */
  96 
  97 int
  98 my_mkdir (const vfs_path_t *vpath, mode_t mode)
     /* [previous][next][first][last][top][bottom][index][help]  */
  99 {
 100     int result;
 101 
 102     result = my_mkdir_rec (vpath, mode);
 103     return result;
 104 }
 105 
 106 /* --------------------------------------------------------------------------------------------- */
 107 
 108 int
 109 my_rmdir (const char *path)
     /* [previous][next][first][last][top][bottom][index][help]  */
 110 {
 111     int result;
 112     vfs_path_t *vpath;
 113 
 114     vpath = vfs_path_from_str_flags (path, VPF_NO_CANON);
 115     // FIXME: Should receive a Wtree!
 116     result = mc_rmdir (vpath);
 117     vfs_path_free (vpath, TRUE);
 118     return result;
 119 }
 120 
 121 /* --------------------------------------------------------------------------------------------- */

/* [previous][next][first][last][top][bottom][index][help]  */