dav/sync.c

changeset 782
3cfe65695a8c
parent 781
08d887af3971
child 783
36a7f2ea7d12
equal deleted inserted replaced
781:08d887af3971 782:3cfe65695a8c
101 fprintf(synclog, "%s", str.ptr); 101 fprintf(synclog, "%s", str.ptr);
102 } 102 }
103 free(str.ptr); 103 free(str.ptr);
104 104
105 va_end(ap); 105 va_end(ap);
106 }
107
108 void log_error(const char *fmt, ...) {
109 va_list ap;
110 va_start(ap, fmt);
111 cxmutstr str = cx_vasprintf(fmt, ap);
112
113 fprintf(stderr, "%s", str.ptr);
114 if(synclog) {
115 fprintf(synclog, "%s", str.ptr);
116 }
117 free(str.ptr);
118
119 va_end(ap);
120 }
121
122
123 int logfile_open(SyncDirectory *dir) {
124 int ret = 0;
125 if(dir && dir->logfile) {
126 char *lf_path = dir->logfile;
127 char *lf_path_fr = NULL;
128 if(dir->logfile[0] != '/') {
129 lf_path = config_file_path(dir->logfile);
130 lf_path_fr = lf_path;
131 }
132
133 synclog = fopen(lf_path, "a");
134 if(!synclog) {
135 fprintf(stderr, "Cannot open logfile %s: %s\n", lf_path, strerror(errno));
136 ret = 1;
137 }
138 if(lf_path_fr) {
139 free(lf_path_fr);
140 }
141 }
142 return ret;
106 } 143 }
107 144
108 /* 145 /*
109 * strcmp version that works with NULL pointers 146 * strcmp version that works with NULL pointers
110 */ 147 */
623 return -1; 660 return -1;
624 } 661 }
625 if(scfg_check_dir(dir)) { 662 if(scfg_check_dir(dir)) {
626 return -1; 663 return -1;
627 } 664 }
665 if(logfile_open(dir)) {
666 return -1;
667 }
628 668
629 if((dir->allow_cmd & SYNC_CMD_PULL) != SYNC_CMD_PULL) { 669 if((dir->allow_cmd & SYNC_CMD_PULL) != SYNC_CMD_PULL) {
630 fprintf(stderr, "Command 'pull' is not allowed for this sync dir\n"); 670 fprintf(stderr, "Command 'pull' is not allowed for this sync dir\n");
631 print_allowed_cmds(dir); 671 print_allowed_cmds(dir);
632 return -1; 672 return -1;
1948 if(!dir) { 1988 if(!dir) {
1949 fprintf(stderr, "Unknown sync dir: %s\n", a->argv[0]); 1989 fprintf(stderr, "Unknown sync dir: %s\n", a->argv[0]);
1950 return -1; 1990 return -1;
1951 } 1991 }
1952 if(scfg_check_dir(dir)) { 1992 if(scfg_check_dir(dir)) {
1993 return -1;
1994 }
1995 if(logfile_open(dir)) {
1953 return -1; 1996 return -1;
1954 } 1997 }
1955 if(cmd_getoption(a, "snapshot")) { 1998 if(cmd_getoption(a, "snapshot")) {
1956 if(dir->versioning) { 1999 if(dir->versioning) {
1957 dir->versioning->always = TRUE; 2000 dir->versioning->always = TRUE;
2539 SyncDirectory *dir = NULL; 2582 SyncDirectory *dir = NULL;
2540 CxMap *files = NULL; 2583 CxMap *files = NULL;
2541 if(syncdir) { 2584 if(syncdir) {
2542 dir = scfg_get_dir(syncdir); 2585 dir = scfg_get_dir(syncdir);
2543 } 2586 }
2587 if(logfile_open(dir)) {
2588 return -1;
2589 }
2544 2590
2545 LocalResource nres; 2591 LocalResource nres;
2546 if(a->argc > 0) { 2592 if(a->argc > 0) {
2547 files = cxHashMapCreate(cxDefaultAllocator, CX_STORE_POINTERS, a->argc+8); 2593 files = cxHashMapCreate(cxDefaultAllocator, CX_STORE_POINTERS, a->argc+8);
2548 // get all specified files and check the syncdir 2594 // get all specified files and check the syncdir
4755 return -1; 4801 return -1;
4756 } 4802 }
4757 if(scfg_check_dir(dir)) { 4803 if(scfg_check_dir(dir)) {
4758 return -1; 4804 return -1;
4759 } 4805 }
4806 if(logfile_open(dir)) {
4807 return -1;
4808 }
4760 4809
4761 SyncDatabase *db = load_db(dir->database); 4810 SyncDatabase *db = load_db(dir->database);
4762 if(!db) { 4811 if(!db) {
4763 fprintf(stderr, "Cannot load database file: %s\n", dir->database); 4812 fprintf(stderr, "Cannot load database file: %s\n", dir->database);
4764 return -1; 4813 return -1;
4802 if(!dir) { 4851 if(!dir) {
4803 fprintf(stderr, "Unknown sync dir: %s\n", a->argv[0]); 4852 fprintf(stderr, "Unknown sync dir: %s\n", a->argv[0]);
4804 return -1; 4853 return -1;
4805 } 4854 }
4806 if(scfg_check_dir(dir)) { 4855 if(scfg_check_dir(dir)) {
4856 return -1;
4857 }
4858 if(logfile_open(dir)) {
4807 return -1; 4859 return -1;
4808 } 4860 }
4809 4861
4810 SyncDatabase *db = load_db(dir->database); 4862 SyncDatabase *db = load_db(dir->database);
4811 if(!db) { 4863 if(!db) {
5174 } 5226 }
5175 5227
5176 SyncDirectory *syncdir = scfg_get_dir(a->argv[0]); 5228 SyncDirectory *syncdir = scfg_get_dir(a->argv[0]);
5177 if(!syncdir) { 5229 if(!syncdir) {
5178 fprintf(stderr, "Unknown sync dir: %s\n", a->argv[0]); 5230 fprintf(stderr, "Unknown sync dir: %s\n", a->argv[0]);
5231 return -1;
5232 }
5233 if(logfile_open(syncdir)) {
5179 return -1; 5234 return -1;
5180 } 5235 }
5181 5236
5182 if(!syncdir->trash) { 5237 if(!syncdir->trash) {
5183 fprintf(stderr, "trash not configured for %s\n", syncdir->name); 5238 fprintf(stderr, "trash not configured for %s\n", syncdir->name);

mercurial