2 * Copyright 2021 Olaf Wintermann
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 * DEALINGS IN THE SOFTWARE.
30 #include <ucx/string.h>
38 #define MZCP_ENV_HOME "HOME"
39 #define MZCP_CFG_BASE ".config"
40 #define MZCP_CFG_DIR ".config/mizunara"
41 #define MZCP_COPY_DIR "copy"
43 #define CLIENT_MSG_BUFSIZE 512
45 #define MAX_COPY_THREADS 32
46 #define MZ_COPY_BUFSIZE 4 * 1024 * 1024
50 typedef struct SrcFile SrcFile;
51 typedef struct MZLock MZLock;
52 typedef struct MZQueue MZQueue;
61 struct stat root_stat;
65 pthread_mutex_t mutex;
71 * src file path relative to CPSettings.from
76 * is the file a directory
99 * processing this file depends on another file (directory)
104 * lock used for waiting, until this resource is successfully copied
114 const char* mzcp_get_cfgdir(void);
115 const char* mzcp_get_copydir(void);
117 int mzcp_copy(CPSettings *settings);
119 int mzcp_start_scan(CPSettings *settings);
120 void* scan_run(void *data);
122 int enqueue_file(SrcFile *file);
124 int mzcp_start_copy_threads(CPSettings *settings);
125 void* copy_run(void *data);
127 int mz_copy_dir(CPSettings *settings, SrcFile *file, const char *from, const char *to);
128 int mz_copy_file(CPSettings *settings, SrcFile *file, const char *from, const char *to, char *buffer, size_t bufsize);