Ticket #2183: edit crash while opening some incorrect files.
[midnight-commander.git] / src / fileopctx.h
blob305fe6389723a198b85471f10d0ff6a9cacfa237
2 /** \file fileopctx.h
3 * \brief Header: file operation contexts
4 * \date 1998
5 * \author Federico Mena <federico@nuclecu.unam.mx>
6 * \author Miguel de Icaza <miguel@nuclecu.unam.mx>
7 */
9 /* File operation contexts for the Midnight Commander
11 * Copyright (C) 1998 Free Software Foundation, Inc.
15 #ifndef FILEOPCTX_H
16 #define FILEOPCTX_H
18 #include <sys/stat.h>
19 #include <sys/types.h>
21 struct mc_search_struct;
22 typedef enum {
23 OP_COPY,
24 OP_MOVE,
25 OP_DELETE
26 } FileOperation;
28 typedef int (*mc_stat_fn) (const char *filename, struct stat *buf);
30 /* This structure describes a context for file operations. It is used to update
31 * the progress windows and pass around options.
33 typedef struct FileOpContext {
34 /* Operation type (copy, move, delete) */
35 FileOperation operation;
37 /* The estimated time of arrival in seconds */
38 double eta_secs;
40 /* Transferred bytes per second */
41 long bps;
43 /* Transferred seconds */
44 long bps_time;
46 /* Whether the panel total has been computed */
47 int progress_totals_computed;
49 /* Counters for progress indicators */
50 off_t progress_count;
51 double progress_bytes;
53 /* The value of the "preserve Attributes" checkbox in the copy file dialog.
54 * We can't use the value of "ctx->preserve" because it can change in order
55 * to preserve file attributs when moving files across filesystem boundaries
56 * (we want to keep the value of the checkbox between copy operations).
58 int op_preserve;
60 /* Result from the recursive query */
61 int recursive_result;
63 /* Whether to do a reget */
64 off_t do_reget;
66 /* Controls appending to files */
67 int do_append;
69 /* Whether to stat or lstat */
70 int follow_links;
72 /* Pointer to the stat function we will use */
73 mc_stat_fn stat_func;
75 /* Whether to recompute symlinks */
76 int stable_symlinks;
78 /* Preserve the original files' owner, group, permissions, and
79 * timestamps (owner, group only as root).
81 int preserve;
83 /* If running as root, preserve the original uid/gid (we don't want to
84 * try chown for non root) preserve_uidgid = preserve && uid == 0
86 int preserve_uidgid;
88 /* The bits to preserve in created files' modes on file copy */
89 int umask_kill;
91 /* The mask of files to actually operate on */
92 char *dest_mask;
94 struct mc_search_struct *search_handle;
95 /* Whether to dive into subdirectories for recursive operations */
96 int dive_into_subdirs;
98 /* When moving directories cross filesystem boundaries delete the
99 * successfully copied files when all files below the directory and its
100 * subdirectories were processed.
102 * If erase_at_end is zero files will be deleted immediately after their
103 * successful copy (Note: this behavior is not tested and at the moment
104 * it can't be changed at runtime).
106 int erase_at_end;
108 /* PID of the child for background operations */
109 pid_t pid;
111 /* User interface data goes here */
113 void *ui;
114 } FileOpContext;
117 FileOpContext *file_op_context_new (FileOperation op);
118 void file_op_context_destroy (FileOpContext *ctx);
121 extern const char *op_names [3];
123 typedef enum {
124 FILE_CONT = 0,
125 FILE_RETRY = 1,
126 FILE_SKIP = 2,
127 FILE_ABORT = 3
128 } FileProgressStatus;
130 typedef enum {
131 RECURSIVE_YES,
132 RECURSIVE_NO,
133 RECURSIVE_ALWAYS,
134 RECURSIVE_NEVER,
135 RECURSIVE_ABORT
136 } FileCopyMode;
138 /* First argument passed to real functions */
139 enum OperationMode {
140 Foreground,
141 Background
144 /* The following functions are implemented separately by each port */
146 void file_op_context_create_ui (FileOpContext *ctx, int with_eta);
147 void file_op_context_create_ui_without_init (FileOpContext *ctx, int with_eta);
148 void file_op_context_destroy_ui (FileOpContext *ctx);
150 FileProgressStatus file_progress_show (FileOpContext *ctx, off_t done, off_t total);
151 FileProgressStatus file_progress_show_count (FileOpContext *ctx, off_t done, off_t total);
152 FileProgressStatus file_progress_show_bytes (FileOpContext *ctx, double done, double total);
153 FileProgressStatus file_progress_show_source (FileOpContext *ctx, const char *path);
154 FileProgressStatus file_progress_show_target (FileOpContext *ctx, const char *path);
155 FileProgressStatus file_progress_show_deleting (FileOpContext *ctx, const char *path);
157 void file_progress_set_stalled_label (FileOpContext *ctx, const char *stalled_msg);
159 FileProgressStatus file_progress_real_query_replace (FileOpContext *ctx,
160 enum OperationMode mode,
161 const char *destname,
162 struct stat *_s_stat,
163 struct stat *_d_stat);
166 #endif