author | Natanael Copa <natanael.copa@gmail.com> | 2008-12-02 10:31:34 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2008-12-28 09:09:18 (UTC) |
commit | c4b45de33458f66f5a768530d738f6c28e56cf49 (patch) (unidiff) | |
tree | 4bbc634befd11509bb73cd978be6edd8deac41fa | |
parent | 06de14d0fdb141feab10383ba18c0e81d56f483b (diff) | |
download | cgit-c4b45de33458f66f5a768530d738f6c28e56cf49.zip cgit-c4b45de33458f66f5a768530d738f6c28e56cf49.tar.gz cgit-c4b45de33458f66f5a768530d738f6c28e56cf49.tar.bz2 |
return 404 if snapshot is not found
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
-rw-r--r-- | ui-snapshot.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/ui-snapshot.c b/ui-snapshot.c index 6f09151..f98f5d7 100644 --- a/ui-snapshot.c +++ b/ui-snapshot.c | |||
@@ -114,79 +114,81 @@ static int make_snapshot(const struct cgit_snapshot_format *format, | |||
114 | return 0; | 114 | return 0; |
115 | } | 115 | } |
116 | 116 | ||
117 | /* Try to guess the requested revision from the requested snapshot name. | 117 | /* Try to guess the requested revision from the requested snapshot name. |
118 | * First the format extension is stripped, e.g. "cgit-0.7.2.tar.gz" become | 118 | * First the format extension is stripped, e.g. "cgit-0.7.2.tar.gz" become |
119 | * "cgit-0.7.2". If this is a valid commit object name we've got a winner. | 119 | * "cgit-0.7.2". If this is a valid commit object name we've got a winner. |
120 | * Otherwise, if the snapshot name has a prefix matching the result from | 120 | * Otherwise, if the snapshot name has a prefix matching the result from |
121 | * repo_basename(), we strip the basename and any following '-' and '_' | 121 | * repo_basename(), we strip the basename and any following '-' and '_' |
122 | * characters ("cgit-0.7.2" -> "0.7.2") and check the resulting name once | 122 | * characters ("cgit-0.7.2" -> "0.7.2") and check the resulting name once |
123 | * more. If this still isn't a valid commit object name, we check if pre- | 123 | * more. If this still isn't a valid commit object name, we check if pre- |
124 | * pending a 'v' to the remaining snapshot name ("0.7.2" -> "v0.7.2") gives | 124 | * pending a 'v' to the remaining snapshot name ("0.7.2" -> "v0.7.2") gives |
125 | * us something valid. | 125 | * us something valid. |
126 | */ | 126 | */ |
127 | static const char *get_ref_from_filename(const char *url, const char *filename, | 127 | static const char *get_ref_from_filename(const char *url, const char *filename, |
128 | const struct cgit_snapshot_format *format) | 128 | const struct cgit_snapshot_format *format) |
129 | { | 129 | { |
130 | const char *reponame; | 130 | const char *reponame; |
131 | unsigned char sha1[20]; | 131 | unsigned char sha1[20]; |
132 | char *snapshot; | 132 | char *snapshot; |
133 | 133 | ||
134 | snapshot = xstrdup(filename); | 134 | snapshot = xstrdup(filename); |
135 | snapshot[strlen(snapshot) - strlen(format->suffix)] = '\0'; | 135 | snapshot[strlen(snapshot) - strlen(format->suffix)] = '\0'; |
136 | fprintf(stderr, "snapshot=%s\n", snapshot); | 136 | fprintf(stderr, "snapshot=%s\n", snapshot); |
137 | 137 | ||
138 | if (get_sha1(snapshot, sha1) == 0) | 138 | if (get_sha1(snapshot, sha1) == 0) |
139 | return snapshot; | 139 | return snapshot; |
140 | 140 | ||
141 | reponame = cgit_repobasename(url); | 141 | reponame = cgit_repobasename(url); |
142 | fprintf(stderr, "reponame=%s\n", reponame); | 142 | fprintf(stderr, "reponame=%s\n", reponame); |
143 | if (prefixcmp(snapshot, reponame) == 0) { | 143 | if (prefixcmp(snapshot, reponame) == 0) { |
144 | snapshot += strlen(reponame); | 144 | snapshot += strlen(reponame); |
145 | while (snapshot && (*snapshot == '-' || *snapshot == '_')) | 145 | while (snapshot && (*snapshot == '-' || *snapshot == '_')) |
146 | snapshot++; | 146 | snapshot++; |
147 | } | 147 | } |
148 | 148 | ||
149 | if (get_sha1(snapshot, sha1) == 0) | 149 | if (get_sha1(snapshot, sha1) == 0) |
150 | return snapshot; | 150 | return snapshot; |
151 | 151 | ||
152 | snapshot = fmt("v%s", snapshot); | 152 | snapshot = fmt("v%s", snapshot); |
153 | if (get_sha1(snapshot, sha1) == 0) | 153 | if (get_sha1(snapshot, sha1) == 0) |
154 | return snapshot; | 154 | return snapshot; |
155 | 155 | ||
156 | return NULL; | 156 | return NULL; |
157 | } | 157 | } |
158 | 158 | ||
159 | void cgit_print_snapshot(const char *head, const char *hex, | 159 | void cgit_print_snapshot(const char *head, const char *hex, |
160 | const char *filename, int snapshots, int dwim) | 160 | const char *filename, int snapshots, int dwim) |
161 | { | 161 | { |
162 | const struct cgit_snapshot_format* f; | 162 | const struct cgit_snapshot_format* f; |
163 | char *prefix = NULL; | 163 | char *prefix = NULL; |
164 | 164 | ||
165 | f = get_format(filename); | 165 | f = get_format(filename); |
166 | if (!f) { | 166 | if (!f) { |
167 | ctx.page.mimetype = "text/html"; | 167 | ctx.page.mimetype = "text/html"; |
168 | cgit_print_http_headers(&ctx); | 168 | cgit_print_http_headers(&ctx); |
169 | cgit_print_docstart(&ctx); | 169 | cgit_print_docstart(&ctx); |
170 | cgit_print_pageheader(&ctx); | 170 | cgit_print_pageheader(&ctx); |
171 | cgit_print_error(fmt("Unsupported snapshot format: %s", filename)); | 171 | cgit_print_error(fmt("Unsupported snapshot format: %s", filename)); |
172 | cgit_print_docend(); | 172 | cgit_print_docend(); |
173 | return; | 173 | return; |
174 | } | 174 | } |
175 | 175 | ||
176 | if (!hex && dwim) { | 176 | if (!hex && dwim) { |
177 | hex = get_ref_from_filename(ctx.repo->url, filename, f); | 177 | hex = get_ref_from_filename(ctx.repo->url, filename, f); |
178 | if (hex != NULL) { | 178 | if (hex == NULL) { |
179 | prefix = xstrdup(filename); | 179 | html_status(404, "Not found", 0); |
180 | prefix[strlen(filename) - strlen(f->suffix)] = '\0'; | 180 | return; |
181 | } | 181 | } |
182 | prefix = xstrdup(filename); | ||
183 | prefix[strlen(filename) - strlen(f->suffix)] = '\0'; | ||
182 | } | 184 | } |
183 | 185 | ||
184 | if (!hex) | 186 | if (!hex) |
185 | hex = head; | 187 | hex = head; |
186 | 188 | ||
187 | if (!prefix) | 189 | if (!prefix) |
188 | prefix = xstrdup(cgit_repobasename(ctx.repo->url)); | 190 | prefix = xstrdup(cgit_repobasename(ctx.repo->url)); |
189 | 191 | ||
190 | make_snapshot(f, hex, prefix, filename); | 192 | make_snapshot(f, hex, prefix, filename); |
191 | free(prefix); | 193 | free(prefix); |
192 | } | 194 | } |