Merge branch '4535_tmpdir_name'
[midnight-commander.git] / src / filemanager / fileopctx.h
blob1c26140dd726511d06c74014c2dd4b416bf09e0d
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 <inttypes.h> /* uintmax_t */
15 #include "lib/global.h"
16 #include "lib/vfs/vfs.h"
19 /*** typedefs(not structures) and defined constants **********************************************/
21 typedef int (*mc_stat_fn) (const vfs_path_t * vpath, struct stat * buf);
23 /*** enums ***************************************************************************************/
25 typedef enum
27 FILEGUI_DIALOG_ONE_ITEM,
28 FILEGUI_DIALOG_MULTI_ITEM,
29 FILEGUI_DIALOG_DELETE_ITEM
30 } filegui_dialog_type_t;
32 typedef enum
34 OP_COPY = 0,
35 OP_MOVE = 1,
36 OP_DELETE = 2
37 } FileOperation;
39 typedef enum
41 RECURSIVE_YES = 0,
42 RECURSIVE_NO = 1,
43 RECURSIVE_ALWAYS = 2,
44 RECURSIVE_NEVER = 3,
45 RECURSIVE_ABORT = 4
46 } FileCopyMode;
48 /* ATTENTION: avoid overlapping with B_* values (lib/widget/dialog.h) */
49 typedef enum
51 FILE_CONT = 10,
52 FILE_RETRY,
53 FILE_SKIP,
54 FILE_ABORT,
55 FILE_SKIPALL,
56 FILE_SUSPEND
57 } FileProgressStatus;
59 /* First argument passed to real functions */
60 enum OperationMode
62 Foreground,
63 Background
66 /*** structures declarations (and typedefs of structures)*****************************************/
68 struct mc_search_struct;
70 /* This structure describes a context for file operations. It is used to update
71 * the progress windows and pass around options.
73 typedef struct
75 /* Operation type (copy, move, delete) */
76 FileOperation operation;
78 /* The estimated time of arrival in seconds */
79 double eta_secs;
81 /* Transferred bytes per second */
82 long bps;
84 /* Transferred seconds */
85 long bps_time;
87 /* Whether the panel total has been computed */
88 gboolean progress_totals_computed;
89 filegui_dialog_type_t dialog_type;
91 /* Counters for progress indicators */
92 size_t progress_count;
93 uintmax_t progress_bytes;
95 /* Result from the recursive query */
96 FileCopyMode recursive_result;
98 /* Whether to do a reget */
99 off_t do_reget;
101 /* Controls appending to files */
102 gboolean do_append;
104 /* Whether to stat or lstat */
105 gboolean follow_links;
107 /* Pointer to the stat function we will use */
108 mc_stat_fn stat_func;
110 /* Whether to recompute symlinks */
111 gboolean stable_symlinks;
113 /* Preserve the original files' owner, group, permissions, and
114 * timestamps (owner, group only as root).
116 gboolean preserve;
118 /* If running as root, preserve the original uid/gid (we don't want to
119 * try chown for non root) preserve_uidgid = preserve && uid == 0
121 gboolean preserve_uidgid;
123 /* The bits to preserve in created files' modes on file copy */
124 mode_t umask_kill;
126 /* The mask of files to actually operate on */
127 char *dest_mask;
129 /* search handler */
130 struct mc_search_struct *search_handle;
132 /* Whether to dive into subdirectories for recursive operations */
133 gboolean dive_into_subdirs;
135 /* When moving directories cross filesystem boundaries delete the
136 * successfully copied files when all files below the directory and its
137 * subdirectories were processed.
139 * If erase_at_end is FALSE files will be deleted immediately after their
140 * successful copy (Note: this behavior is not tested and at the moment
141 * it can't be changed at runtime).
143 gboolean erase_at_end;
145 /* PID of the child for background operations */
146 pid_t pid;
148 /* toggle if all errors should be ignored */
149 gboolean skip_all;
151 /* Whether the file operation is in pause */
152 gboolean suspended;
154 /* User interface data goes here */
155 void *ui;
156 } file_op_context_t;
158 typedef struct
160 size_t progress_count;
161 size_t prev_progress_count; /* Used in OP_MOVE between copy and remove directories */
162 uintmax_t progress_bytes;
163 uintmax_t copied_bytes;
164 size_t bps;
165 size_t bps_count;
166 gint64 transfer_start;
167 double eta_secs;
169 gboolean ask_overwrite;
170 } file_op_total_context_t;
172 /*** global variables defined in .c file *********************************************************/
174 extern const char *op_names[3];
176 /*** declarations of public functions ************************************************************/
178 file_op_context_t *file_op_context_new (FileOperation op);
179 void file_op_context_destroy (file_op_context_t * ctx);
181 file_op_total_context_t *file_op_total_context_new (void);
182 void file_op_total_context_destroy (file_op_total_context_t * tctx);
184 /* The following functions are implemented separately by each port */
185 FileProgressStatus file_progress_real_query_replace (file_op_context_t * ctx,
186 enum OperationMode mode, const char *src,
187 struct stat *src_stat, const char *dst,
188 struct stat *dst_stat);
190 /*** inline functions ****************************************************************************/
191 #endif /* MC__FILEOPCTX_H */