1 /* vifm 2 * Copyright (C) 2011 xaizek. 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 */ 18 19 #ifndef VIFM__OPS_H__ 20 #define VIFM__OPS_H__ 21 22 #include "io/ioeta.h" 23 24 /* Kinds of operations on files. */ 25 typedef enum 26 { 27 OP_NONE, 28 OP_USR, 29 OP_REMOVE, /* rm -rf */ 30 OP_REMOVESL, /* cl */ 31 OP_COPY, /* copy and clone */ 32 OP_COPYF, /* copy with file overwrite */ 33 OP_COPYA, /* copy with appending to existing contents of destination */ 34 OP_MOVE, /* move, rename and substitute */ 35 OP_MOVEF, /* move with file overwrite */ 36 OP_MOVEA, /* move file appending to existing contents of destination */ 37 OP_MOVETMP1, /* multiple files rename */ 38 OP_MOVETMP2, /* multiple files rename */ 39 OP_MOVETMP3, /* multiple files rename */ 40 OP_MOVETMP4, /* multiple files rename */ 41 OP_CHOWN, 42 OP_CHGRP, 43 #ifndef _WIN32 44 OP_CHMOD, 45 OP_CHMODR, 46 #else 47 OP_ADDATTR, 48 OP_SUBATTR, 49 #endif 50 OP_SYMLINK, 51 OP_SYMLINK2, 52 OP_MKDIR, 53 OP_RMDIR, 54 OP_MKFILE, 55 OP_COUNT 56 } 57 OPS; 58 59 /* Policy on treating conflicts during operation processing. */ 60 typedef enum 61 { 62 CRP_ASK, /* Prompt user for the decision. */ 63 CRP_SKIP_ALL, /* Automatically skip file. */ 64 CRP_OVERWRITE_ALL, /* Automatically overwrite file. */ 65 } 66 ConflictResolutionPolicy; 67 68 /* Policy on treating errors during operation processing. */ 69 typedef enum 70 { 71 ERP_ASK, /* Prompt user for the decision. */ 72 ERP_IGNORE_ALL, /* Automatically ignore all future errors. */ 73 } 74 ErrorResolutionPolicy; 75 76 /* Description of file operation on a set of files. Collects information and 77 * helps to keep track of progress. */ 78 typedef struct 79 { 80 OPS main_op; /* Primary operation performed on items. */ 81 int total; /* Total number of items to be processed. */ 82 int current; /* Number of current item. */ 83 int succeeded; /* Number of successfully processed items. */ 84 ioeta_estim_t *estim; /* When non-NULL, populated with estimates for items 85 and also frees it on ops_free(). */ 86 const char *descr; /* Description of operations. */ 87 int shallow_eta; /* Count only top level items, without recursion. */ 88 int bg; /* Executed in background (no user interaction). */ 89 struct bg_op_t *bg_op; /* Information for background operation. */ 90 char *errors; /* Multi-line string of errors. */ 91 92 /* It's unsafe to access global cfg object from threads performing background 93 * operations, so copy them and use the copies. */ 94 char *slow_fs_list; /* Copy of 'slowfs' option value. */ 95 char *delete_prg; /* Copy of 'deleteprg' option value. */ 96 int use_system_calls; /* Copy of 'syscalls' option value. */ 97 int fast_file_cloning; /* Copy of part of 'iooptions' option value. */ 98 99 char *base_dir; /* Base directory in which operation is taking place. */ 100 char *target_dir; /* Target directory of the operation (same as base_dir if 101 none). */ 102 103 ConflictResolutionPolicy crp; /* What should be done on conflicts. */ 104 ErrorResolutionPolicy erp; /* What should be done on unexpected errors. */ 105 106 /* TODO: count number of skipped files. */ 107 } 108 ops_t; 109 110 /* Allocates and initializes new ops_t. Returns just allocated structure. */ 111 ops_t * ops_alloc(OPS main_op, int bg, const char descr[], 112 const char base_dir[], const char target_dir[]); 113 114 /* Describes main operation with one generic word. Returns the description. */ 115 const char * ops_describe(const ops_t *ops); 116 117 /* Puts new item to the ops. Destination argument is a hint to optimize 118 * estimating performance, it can be NULL. */ 119 void ops_enqueue(ops_t *ops, const char src[], const char dst[]); 120 121 /* Advances ops to the next item. */ 122 void ops_advance(ops_t *ops, int succeeded); 123 124 /* Frees ops_t. The ops can be NULL. */ 125 void ops_free(ops_t *ops); 126 127 /* Performs single operations, possibly part of the ops (which can be NULL). 128 * Returns non-zero on error, otherwise zero is returned. */ 129 int perform_operation(OPS op, ops_t *ops, void *data, const char src[], 130 const char dst[]); 131 132 #endif /* VIFM__OPS_H__ */ 133 134 /* vim: set tabstop=2 softtabstop=2 shiftwidth=2 noexpandtab cinoptions-=(0 : */ 135 /* vim: set cinoptions+=t0 filetype=c : */ 136