dav/tar.c

changeset 747
efbd59642577
parent 499
efd8f489d415
child 785
645f7e802873
equal deleted inserted replaced
746:a569148841ff 747:efbd59642577
27 */ 27 */
28 28
29 #include "tar.h" 29 #include "tar.h"
30 30
31 #include <string.h> 31 #include <string.h>
32 #include <ucx/string.h> 32 #include <cx/string.h>
33 #include <libidav/utils.h> 33 #include <libidav/utils.h>
34 34
35 35
36 const char* tar_error2str(TarError error) { 36 const char* tar_error2str(TarError error) {
37 switch(error) { 37 switch(error) {
57 57
58 58
59 static int add_header(TarOutputStream *tar, char *path, uint32_t mode, uint64_t size, time_t mtime, int type) { 59 static int add_header(TarOutputStream *tar, char *path, uint32_t mode, uint64_t size, time_t mtime, int type) {
60 // split path in prefix and name and check length 60 // split path in prefix and name and check length
61 char *p = util_parent_path(path); 61 char *p = util_parent_path(path);
62 char *n = util_resource_name(path); 62 const char *n = util_resource_name(path);
63 if(!p || !n) { 63 if(!p || !n) {
64 return -1; 64 return -1;
65 } 65 }
66 66
67 sstr_t prefix = sstr(p); 67 cxstring prefix = cx_str(p);
68 sstr_t name = sstr(n); 68 cxstring name = cx_str(n);
69 69
70 if(prefix.ptr[prefix.length-1] == '/') { 70 if(prefix.ptr[prefix.length-1] == '/') {
71 prefix.length--; 71 prefix.length--;
72 } 72 }
73 73
74 if(prefix.length > 154) { 74 if(prefix.length > 154) {
75 tar->error = TAR_PATH_TOO_LONG; 75 tar->error = TAR_PATH_TOO_LONG;
76 free(p);
76 return -1; 77 return -1;
77 } 78 }
78 if(name.length > 99) { 79 if(name.length > 99) {
79 tar->error = TAR_PATH_TOO_LONG; 80 tar->error = TAR_PATH_TOO_LONG;
81 free(p);
80 return -1; 82 return -1;
81 } 83 }
82 84
83 // check file length 85 // check file length
84 if(size >= 077777777777 ) { 86 if(size >= 077777777777 ) {
85 tar->error = TAR_FILE_TOO_LARGE; 87 tar->error = TAR_FILE_TOO_LARGE;
88 free(p);
86 return -1; 89 return -1;
87 } 90 }
88 91
89 // set header fields 92 // set header fields
90 TarHeader h; 93 TarHeader h;
134 } 137 }
135 snprintf(h.chksum, 8, "%07o", chksum); 138 snprintf(h.chksum, 8, "%07o", chksum);
136 139
137 fwrite(&h, 1, 512, tar->file); 140 fwrite(&h, 1, 512, tar->file);
138 141
142 free(p);
143
139 return 0; 144 return 0;
140 } 145 }
141 146
142 147
143 int tar_add_dir(TarOutputStream *tar, char *path, uint32_t mode, time_t mtime) { 148 int tar_add_dir(TarOutputStream *tar, char *path, uint32_t mode, time_t mtime) {

mercurial