Ticket #3913: implement safe file overwrite.
[midnight-commander.git] / src / filemanager / fileopctx.h
blob07c94f36abfe039a7c1bbd446765b65af2488c50
1 /** \file fileopctx.h
2 * \brief Header: file operation contexts
3 * \date 1998
4 * \author Federico Mena <federico@nuclecu.unam.mx>
5 * \author Miguel de Icaza <miguel@nuclecu.unam.mx>
6 */
8 #ifndef MC__FILEOPCTX_H
9 #define MC__FILEOPCTX_H
11 #include <sys/stat.h>
12 #include <sys/types.h>
13 #include <sys/time.h>
14 #include <inttypes.h> /* uintmax_t */
16 #include "lib/global.h"
17 #include "lib/vfs/vfs.h"
20 /*** typedefs(not structures) and defined constants **********************************************/
22 typedef int (*mc_stat_fn) (const vfs_path_t * vpath, struct stat * buf);
24 /*** enums ***************************************************************************************/
26 typedef enum
28 FILEGUI_DIALOG_ONE_ITEM,
29 FILEGUI_DIALOG_MULTI_ITEM,
30 FILEGUI_DIALOG_DELETE_ITEM
31 } filegui_dialog_type_t;
33 typedef enum
35 OP_COPY = 0,
36 OP_MOVE = 1,
37 OP_DELETE = 2
38 } FileOperation;
40 typedef enum
42 RECURSIVE_YES = 0,
43 RECURSIVE_NO = 1,
44 RECURSIVE_ALWAYS = 2,
45 RECURSIVE_NEVER = 3,
46 RECURSIVE_ABORT = 4
47 } FileCopyMode;
49 /* ATTENTION: avoid overlapping with B_* values (lib/widget/dialog.h) */
50 typedef enum
52 FILE_CONT = 10,
53 FILE_RETRY,
54 FILE_SKIP,
55 FILE_ABORT,
56 FILE_SKIPALL,
57 FILE_SUSPEND
58 } FileProgressStatus;
60 /* First argument passed to real functions */
61 enum OperationMode
63 Foreground,
64 Background
67 /*** structures declarations (and typedefs of structures)*****************************************/
69 struct mc_search_struct;
71 /* This structure describes a context for file operations. It is used to update
72 * the progress windows and pass around options.
74 typedef struct
76 /* Operation type (copy, move, delete) */
77 FileOperation operation;
79 /* The estimated time of arrival in seconds */
80 double eta_secs;
82 /* Transferred bytes per second */
83 long bps;
85 /* Transferred seconds */
86 long bps_time;
88 /* Whether the panel total has been computed */
89 gboolean progress_totals_computed;
90 filegui_dialog_type_t dialog_type;
92 /* Counters for progress indicators */
93 size_t progress_count;
94 uintmax_t progress_bytes;
96 /* The value of the "preserve Attributes" checkbox in the copy file dialog.
97 * We can't use the value of "ctx->preserve" because it can change in order
98 * to preserve file attributs when moving files across filesystem boundaries
99 * (we want to keep the value of the checkbox between copy operations).
101 gboolean op_preserve;
103 /* Result from the recursive query */
104 FileCopyMode recursive_result;
106 /* Whether to do a reget */
107 off_t do_reget;
109 /* Controls appending to files */
110 gboolean do_append;
112 /* Whether to stat or lstat */
113 gboolean follow_links;
115 /* Pointer to the stat function we will use */
116 mc_stat_fn stat_func;
118 /* Whether to recompute symlinks */
119 gboolean stable_symlinks;
121 /* Preserve the original files' owner, group, permissions, and
122 * timestamps (owner, group only as root).
124 gboolean preserve;
126 /* If running as root, preserve the original uid/gid (we don't want to
127 * try chown for non root) preserve_uidgid = preserve && uid == 0
129 gboolean preserve_uidgid;
131 /* The bits to preserve in created files' modes on file copy */
132 mode_t umask_kill;
134 /* The mask of files to actually operate on */
135 char *dest_mask;
137 /* search handler */
138 struct mc_search_struct *search_handle;
140 /* Whether to dive into subdirectories for recursive operations */
141 gboolean dive_into_subdirs;
143 /* When moving directories cross filesystem boundaries delete the
144 * successfully copied files when all files below the directory and its
145 * subdirectories were processed.
147 * If erase_at_end is FALSE files will be deleted immediately after their
148 * successful copy (Note: this behavior is not tested and at the moment
149 * it can't be changed at runtime).
151 gboolean erase_at_end;
153 /* PID of the child for background operations */
154 pid_t pid;
156 /* toggle if all errors should be ignored */
157 gboolean skip_all;
159 /* Whether the file operation is in pause */
160 gboolean suspended;
162 /* User interface data goes here */
163 void *ui;
164 } file_op_context_t;
166 typedef struct
168 size_t progress_count;
169 size_t prev_progress_count; /* Used in OP_MOVE between copy and remove directories */
170 uintmax_t progress_bytes;
171 uintmax_t copied_bytes;
172 size_t bps;
173 size_t bps_count;
174 struct timeval transfer_start;
175 double eta_secs;
177 gboolean ask_overwrite;
178 } file_op_total_context_t;
180 /*** global variables defined in .c file *********************************************************/
182 extern const char *op_names[3];
184 /*** declarations of public functions ************************************************************/
186 file_op_context_t *file_op_context_new (FileOperation op);
187 void file_op_context_destroy (file_op_context_t * ctx);
189 file_op_total_context_t *file_op_total_context_new (void);
190 void file_op_total_context_destroy (file_op_total_context_t * tctx);
192 /* The following functions are implemented separately by each port */
193 FileProgressStatus file_progress_real_query_replace (file_op_context_t * ctx,
194 enum OperationMode mode,
195 const char *destname,
196 struct stat *_s_stat, struct stat *_d_stat);
198 /*** inline functions ****************************************************************************/
199 #endif /* MC__FILEOPCTX_H */