summaryrefslogtreecommitdiffstats
path: root/src/filemanager/fileopctx.c
blob: a11874914475e9aa6e2d79d8ab331a72994793f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
   File operation contexts for the Midnight Commander

   Copyright (C) 1999-2023
   Free Software Foundation, Inc.

   Written by:
   Federico Mena <federico@nuclecu.unam.mx>
   Miguel de Icaza <miguel@nuclecu.unam.mx>

   This file is part of the Midnight Commander.

   The Midnight Commander is free software: you can redistribute it
   and/or modify it under the terms of the GNU General Public License as
   published by the Free Software Foundation, either version 3 of the License,
   or (at your option) any later version.

   The Midnight Commander is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/** \file fileopctx.c
 *  \brief Source: file operation contexts
 *  \date 1998-2007
 *  \author Federico Mena <federico@nuclecu.unam.mx>
 *  \author Miguel de Icaza <miguel@nuclecu.unam.mx>
 */

#include <config.h>

#include <unistd.h>

#include "lib/global.h"
#include "fileopctx.h"
#include "filegui.h"
#include "lib/search.h"
#include "lib/vfs/vfs.h"

/*** global variables ****************************************************************************/

/*** file scope macro definitions ****************************************************************/

/*** file scope type declarations ****************************************************************/

/*** file scope variables ************************************************************************/

/*** file scope functions ************************************************************************/
/* --------------------------------------------------------------------------------------------- */

/* --------------------------------------------------------------------------------------------- */
/*** public functions ****************************************************************************/
/* --------------------------------------------------------------------------------------------- */

/**
 * \fn file_op_context_t * file_op_context_new (FileOperation op)
 * \param op file operation struct
 * \return The newly-created context, filled with the default file mask values.
 *
 * Creates a new file operation context with the default values.  If you later want
 * to have a user interface for this, call file_op_context_create_ui().
 */

file_op_context_t *
file_op_context_new (FileOperation op)
{
    file_op_context_t *ctx;

    ctx = g_new0 (file_op_context_t, 1);
    ctx->operation = op;
    ctx->eta_secs = 0.0;
    ctx->progress_bytes = 0;
    ctx->op_preserve = TRUE;
    ctx->do_reget = 1;
    ctx->stat_func = mc_lstat;
    ctx->preserve = TRUE;
    ctx->preserve_uidgid = (geteuid () == 0);
    ctx->umask_kill = 0777777;
    ctx->erase_at_end = TRUE;
    ctx->skip_all = FALSE;

    return ctx;
}

/* --------------------------------------------------------------------------------------------- */
/**
 * \fn void file_op_context_destroy (file_op_context_t *ctx)
 * \param ctx The file operation context to destroy.
 *
 * Destroys the specified file operation context and its associated UI data, if
 * it exists.
 */

void
file_op_context_destroy (file_op_context_t * ctx)
{
    if (ctx != NULL)
    {
        file_op_context_destroy_ui (ctx);
        mc_search_free (ctx->search_handle);
        g_free (ctx);
    }
}

/* --------------------------------------------------------------------------------------------- */

file_op_total_context_t *
file_op_total_context_new (void)
{
    file_op_total_context_t *tctx;
    tctx = g_new0 (file_op_total_context_t, 1);
    tctx->ask_overwrite = TRUE;
    return tctx;
}

/* --------------------------------------------------------------------------------------------- */

void
file_op_total_context_destroy (file_op_total_context_t * tctx)
{
    g_free (tctx);
}

/* --------------------------------------------------------------------------------------------- */