Blame


1 86c3caaf 2018-03-09 stsp /*
2 86c3caaf 2018-03-09 stsp * Copyright (c) 2018 Stefan Sperling <stsp@openbsd.org>
3 86c3caaf 2018-03-09 stsp *
4 86c3caaf 2018-03-09 stsp * Permission to use, copy, modify, and distribute this software for any
5 86c3caaf 2018-03-09 stsp * purpose with or without fee is hereby granted, provided that the above
6 86c3caaf 2018-03-09 stsp * copyright notice and this permission notice appear in all copies.
7 86c3caaf 2018-03-09 stsp *
8 86c3caaf 2018-03-09 stsp * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 86c3caaf 2018-03-09 stsp * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 86c3caaf 2018-03-09 stsp * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 86c3caaf 2018-03-09 stsp * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 86c3caaf 2018-03-09 stsp * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 86c3caaf 2018-03-09 stsp * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 86c3caaf 2018-03-09 stsp * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 86c3caaf 2018-03-09 stsp */
16 86c3caaf 2018-03-09 stsp
17 86c3caaf 2018-03-09 stsp #include <sys/stat.h>
18 6d9d28c3 2018-03-11 stsp #include <sys/limits.h>
19 86c3caaf 2018-03-09 stsp
20 86c3caaf 2018-03-09 stsp #include <string.h>
21 86c3caaf 2018-03-09 stsp #include <stdio.h>
22 86c3caaf 2018-03-09 stsp #include <stdlib.h>
23 86c3caaf 2018-03-09 stsp #include <fcntl.h>
24 86c3caaf 2018-03-09 stsp #include <errno.h>
25 86c3caaf 2018-03-09 stsp #include <unistd.h>
26 86c3caaf 2018-03-09 stsp
27 86c3caaf 2018-03-09 stsp #include "got_error.h"
28 86c3caaf 2018-03-09 stsp #include "got_repository.h"
29 86c3caaf 2018-03-09 stsp #include "got_refs.h"
30 86c3caaf 2018-03-09 stsp #include "got_worktree.h"
31 86c3caaf 2018-03-09 stsp
32 86c3caaf 2018-03-09 stsp #include "got_worktree_priv.h"
33 86c3caaf 2018-03-09 stsp #include "got_path_priv.h"
34 86c3caaf 2018-03-09 stsp
35 99724ed4 2018-03-10 stsp static const struct got_error *
36 99724ed4 2018-03-10 stsp create_meta_file(const char *gotpath, const char *name, const char *content)
37 99724ed4 2018-03-10 stsp {
38 99724ed4 2018-03-10 stsp const struct got_error *err = NULL;
39 99724ed4 2018-03-10 stsp char *path;
40 99724ed4 2018-03-10 stsp int fd = -1;
41 99724ed4 2018-03-10 stsp char buf[4];
42 99724ed4 2018-03-10 stsp ssize_t n;
43 99724ed4 2018-03-10 stsp
44 99724ed4 2018-03-10 stsp if (asprintf(&path, "%s/%s", gotpath, name) == -1) {
45 99724ed4 2018-03-10 stsp err = got_error(GOT_ERR_NO_MEM);
46 99724ed4 2018-03-10 stsp path = NULL;
47 99724ed4 2018-03-10 stsp goto done;
48 99724ed4 2018-03-10 stsp }
49 99724ed4 2018-03-10 stsp
50 73a5ef67 2018-03-11 stsp fd = open(path, O_RDWR | O_CREAT | O_EXCL | O_NOFOLLOW,
51 99724ed4 2018-03-10 stsp GOT_DEFAULT_FILE_MODE);
52 99724ed4 2018-03-10 stsp if (fd == -1) {
53 99724ed4 2018-03-10 stsp err = got_error_from_errno();
54 99724ed4 2018-03-10 stsp goto done;
55 99724ed4 2018-03-10 stsp }
56 99724ed4 2018-03-10 stsp
57 99724ed4 2018-03-10 stsp /* The file should be empty. */
58 99724ed4 2018-03-10 stsp n = read(fd, buf, sizeof(buf));
59 99724ed4 2018-03-10 stsp if (n != 0) {
60 99724ed4 2018-03-10 stsp err = (n == -1 ? got_error_from_errno() :
61 99724ed4 2018-03-10 stsp got_error(GOT_ERR_WORKTREE_EXISTS));
62 99724ed4 2018-03-10 stsp goto done;
63 99724ed4 2018-03-10 stsp }
64 99724ed4 2018-03-10 stsp
65 99724ed4 2018-03-10 stsp if (content) {
66 99724ed4 2018-03-10 stsp int len = dprintf(fd, "%s\n", content);
67 99724ed4 2018-03-10 stsp if (len != strlen(content) + 1) {
68 99724ed4 2018-03-10 stsp err = got_error_from_errno();
69 99724ed4 2018-03-10 stsp goto done;
70 99724ed4 2018-03-10 stsp }
71 99724ed4 2018-03-10 stsp }
72 99724ed4 2018-03-10 stsp
73 99724ed4 2018-03-10 stsp done:
74 99724ed4 2018-03-10 stsp if (fd != -1 && close(fd) == -1 && err == NULL)
75 99724ed4 2018-03-10 stsp err = got_error_from_errno();
76 99724ed4 2018-03-10 stsp free(path);
77 99724ed4 2018-03-10 stsp return err;
78 99724ed4 2018-03-10 stsp }
79 99724ed4 2018-03-10 stsp
80 09fe317a 2018-03-11 stsp static const struct got_error *
81 09fe317a 2018-03-11 stsp read_meta_file(char **content, const char *gotpath, const char *name)
82 09fe317a 2018-03-11 stsp {
83 09fe317a 2018-03-11 stsp const struct got_error *err = NULL;
84 09fe317a 2018-03-11 stsp char *path;
85 09fe317a 2018-03-11 stsp int fd = -1;
86 09fe317a 2018-03-11 stsp ssize_t n;
87 09fe317a 2018-03-11 stsp struct stat sb;
88 09fe317a 2018-03-11 stsp
89 09fe317a 2018-03-11 stsp *content = NULL;
90 09fe317a 2018-03-11 stsp
91 09fe317a 2018-03-11 stsp if (asprintf(&path, "%s/%s", gotpath, name) == -1) {
92 09fe317a 2018-03-11 stsp err = got_error(GOT_ERR_NO_MEM);
93 09fe317a 2018-03-11 stsp path = NULL;
94 09fe317a 2018-03-11 stsp goto done;
95 09fe317a 2018-03-11 stsp }
96 09fe317a 2018-03-11 stsp
97 ef99fdb1 2018-03-11 stsp fd = open(path, O_RDONLY | O_NOFOLLOW);
98 09fe317a 2018-03-11 stsp if (fd == -1) {
99 ef99fdb1 2018-03-11 stsp err = got_error_from_errno();
100 ef99fdb1 2018-03-11 stsp goto done;
101 ef99fdb1 2018-03-11 stsp }
102 ef99fdb1 2018-03-11 stsp if (flock(fd, LOCK_SH | LOCK_NB) == -1) {
103 73a5ef67 2018-03-11 stsp err = (errno == EWOULDBLOCK ? got_error(GOT_ERR_WORKTREE_BUSY)
104 73a5ef67 2018-03-11 stsp : got_error_from_errno());
105 09fe317a 2018-03-11 stsp goto done;
106 09fe317a 2018-03-11 stsp }
107 09fe317a 2018-03-11 stsp
108 09fe317a 2018-03-11 stsp stat(path, &sb);
109 09fe317a 2018-03-11 stsp *content = calloc(1, sb.st_size);
110 09fe317a 2018-03-11 stsp if (*content == NULL) {
111 09fe317a 2018-03-11 stsp err = got_error(GOT_ERR_NO_MEM);
112 09fe317a 2018-03-11 stsp goto done;
113 09fe317a 2018-03-11 stsp }
114 09fe317a 2018-03-11 stsp
115 09fe317a 2018-03-11 stsp n = read(fd, *content, sb.st_size);
116 09fe317a 2018-03-11 stsp if (n != sb.st_size) {
117 09fe317a 2018-03-11 stsp err = got_error_from_errno();
118 09fe317a 2018-03-11 stsp goto done;
119 09fe317a 2018-03-11 stsp }
120 09fe317a 2018-03-11 stsp if ((*content)[sb.st_size - 1] != '\n') {
121 09fe317a 2018-03-11 stsp err = got_error(GOT_ERR_WORKTREE_META);
122 09fe317a 2018-03-11 stsp goto done;
123 09fe317a 2018-03-11 stsp }
124 09fe317a 2018-03-11 stsp (*content)[sb.st_size - 1] = '\0';
125 09fe317a 2018-03-11 stsp
126 09fe317a 2018-03-11 stsp done:
127 09fe317a 2018-03-11 stsp if (fd != -1 && close(fd) == -1 && err == NULL)
128 09fe317a 2018-03-11 stsp err = got_error_from_errno();
129 09fe317a 2018-03-11 stsp free(path);
130 09fe317a 2018-03-11 stsp if (err) {
131 09fe317a 2018-03-11 stsp free(*content);
132 09fe317a 2018-03-11 stsp *content = NULL;
133 09fe317a 2018-03-11 stsp }
134 09fe317a 2018-03-11 stsp return err;
135 09fe317a 2018-03-11 stsp }
136 09fe317a 2018-03-11 stsp
137 86c3caaf 2018-03-09 stsp const struct got_error *
138 86c3caaf 2018-03-09 stsp got_worktree_init(const char *path, struct got_reference *head_ref,
139 577ec78f 2018-03-11 stsp const char *prefix, struct got_repository *repo)
140 86c3caaf 2018-03-09 stsp {
141 86c3caaf 2018-03-09 stsp const struct got_error *err = NULL;
142 86c3caaf 2018-03-09 stsp char *gotpath = NULL;
143 86c3caaf 2018-03-09 stsp char *refstr = NULL;
144 86c3caaf 2018-03-09 stsp char *path_repos = NULL;
145 1451e70d 2018-03-10 stsp char *formatstr = NULL;
146 86c3caaf 2018-03-09 stsp
147 577ec78f 2018-03-11 stsp if (!got_path_is_absolute(prefix))
148 577ec78f 2018-03-11 stsp return got_error(GOT_ERR_BAD_PATH);
149 577ec78f 2018-03-11 stsp
150 86c3caaf 2018-03-09 stsp /* Create top-level directory (may already exist). */
151 2cb4bacb 2018-03-11 stsp if (mkdir(path, GOT_DEFAULT_DIR_MODE) == -1 && errno != EEXIST) {
152 86c3caaf 2018-03-09 stsp err = got_error_from_errno();
153 86c3caaf 2018-03-09 stsp goto done;
154 86c3caaf 2018-03-09 stsp }
155 86c3caaf 2018-03-09 stsp
156 86c3caaf 2018-03-09 stsp /* Create .got directory (may already exist). */
157 2cb4bacb 2018-03-11 stsp if (asprintf(&gotpath, "%s/%s", path, GOT_WORKTREE_GOT_DIR) == -1) {
158 86c3caaf 2018-03-09 stsp err = got_error(GOT_ERR_NO_MEM);
159 86c3caaf 2018-03-09 stsp goto done;
160 86c3caaf 2018-03-09 stsp }
161 86c3caaf 2018-03-09 stsp if (mkdir(gotpath, GOT_DEFAULT_DIR_MODE) == -1 && errno != EEXIST) {
162 86c3caaf 2018-03-09 stsp err = got_error_from_errno();
163 86c3caaf 2018-03-09 stsp goto done;
164 86c3caaf 2018-03-09 stsp }
165 86c3caaf 2018-03-09 stsp
166 86c3caaf 2018-03-09 stsp /* Create an empty file index. */
167 99724ed4 2018-03-10 stsp err = create_meta_file(gotpath, GOT_WORKTREE_FILE_INDEX, NULL);
168 99724ed4 2018-03-10 stsp if (err)
169 86c3caaf 2018-03-09 stsp goto done;
170 86c3caaf 2018-03-09 stsp
171 86c3caaf 2018-03-09 stsp /* Write the HEAD reference. */
172 86c3caaf 2018-03-09 stsp refstr = got_ref_to_str(head_ref);
173 86c3caaf 2018-03-09 stsp if (refstr == NULL) {
174 86c3caaf 2018-03-09 stsp err = got_error(GOT_ERR_NO_MEM);
175 86c3caaf 2018-03-09 stsp goto done;
176 86c3caaf 2018-03-09 stsp }
177 99724ed4 2018-03-10 stsp err = create_meta_file(gotpath, GOT_REF_HEAD, refstr);
178 99724ed4 2018-03-10 stsp if (err)
179 86c3caaf 2018-03-09 stsp goto done;
180 86c3caaf 2018-03-09 stsp
181 1451e70d 2018-03-10 stsp /* Store path to repository. */
182 86c3caaf 2018-03-09 stsp path_repos = got_repo_get_path(repo);
183 86c3caaf 2018-03-09 stsp if (path_repos == NULL) {
184 86c3caaf 2018-03-09 stsp err = got_error(GOT_ERR_NO_MEM);
185 86c3caaf 2018-03-09 stsp goto done;
186 86c3caaf 2018-03-09 stsp }
187 99724ed4 2018-03-10 stsp err = create_meta_file(gotpath, GOT_WORKTREE_REPOSITORY, path_repos);
188 99724ed4 2018-03-10 stsp if (err)
189 86c3caaf 2018-03-09 stsp goto done;
190 86c3caaf 2018-03-09 stsp
191 577ec78f 2018-03-11 stsp /* Store in-repository path prefix. */
192 577ec78f 2018-03-11 stsp err = create_meta_file(gotpath, GOT_WORKTREE_PATH_PREFIX, prefix);
193 577ec78f 2018-03-11 stsp if (err)
194 577ec78f 2018-03-11 stsp goto done;
195 577ec78f 2018-03-11 stsp
196 9dce68ed 2018-03-10 stsp /* Stamp work tree with format file. */
197 1451e70d 2018-03-10 stsp if (asprintf(&formatstr, "%d", GOT_WORKTREE_FORMAT_VERSION) == -1) {
198 1451e70d 2018-03-10 stsp err = got_error(GOT_ERR_NO_MEM);
199 1451e70d 2018-03-10 stsp goto done;
200 1451e70d 2018-03-10 stsp }
201 99724ed4 2018-03-10 stsp err = create_meta_file(gotpath, GOT_WORKTREE_FORMAT, formatstr);
202 99724ed4 2018-03-10 stsp if (err)
203 1451e70d 2018-03-10 stsp goto done;
204 1451e70d 2018-03-10 stsp
205 86c3caaf 2018-03-09 stsp done:
206 86c3caaf 2018-03-09 stsp free(gotpath);
207 1451e70d 2018-03-10 stsp free(formatstr);
208 86c3caaf 2018-03-09 stsp free(refstr);
209 86c3caaf 2018-03-09 stsp free(path_repos);
210 86c3caaf 2018-03-09 stsp return err;
211 86c3caaf 2018-03-09 stsp }
212 86c3caaf 2018-03-09 stsp
213 86c3caaf 2018-03-09 stsp const struct got_error *
214 86c3caaf 2018-03-09 stsp got_worktree_open(struct got_worktree **worktree, const char *path)
215 86c3caaf 2018-03-09 stsp {
216 6d9d28c3 2018-03-11 stsp const struct got_error *err = NULL;
217 6d9d28c3 2018-03-11 stsp char *gotpath;
218 6d9d28c3 2018-03-11 stsp char *refstr = NULL;
219 6d9d28c3 2018-03-11 stsp char *path_repos = NULL;
220 6d9d28c3 2018-03-11 stsp char *formatstr = NULL;
221 6d9d28c3 2018-03-11 stsp char *path_fileindex = NULL;
222 6d9d28c3 2018-03-11 stsp int version, fd = -1;
223 6d9d28c3 2018-03-11 stsp const char *errstr;
224 6d9d28c3 2018-03-11 stsp
225 6d9d28c3 2018-03-11 stsp *worktree = NULL;
226 6d9d28c3 2018-03-11 stsp
227 6d9d28c3 2018-03-11 stsp if (asprintf(&gotpath, "%s/%s", path, GOT_WORKTREE_GOT_DIR) == -1) {
228 6d9d28c3 2018-03-11 stsp err = got_error(GOT_ERR_NO_MEM);
229 6d9d28c3 2018-03-11 stsp gotpath = NULL;
230 6d9d28c3 2018-03-11 stsp goto done;
231 6d9d28c3 2018-03-11 stsp }
232 6d9d28c3 2018-03-11 stsp
233 6d9d28c3 2018-03-11 stsp if (asprintf(&path_fileindex, "%s/%s", gotpath,
234 6d9d28c3 2018-03-11 stsp GOT_WORKTREE_FILE_INDEX) == -1) {
235 6d9d28c3 2018-03-11 stsp err = got_error(GOT_ERR_NO_MEM);
236 6d9d28c3 2018-03-11 stsp path_fileindex = NULL;
237 6d9d28c3 2018-03-11 stsp goto done;
238 6d9d28c3 2018-03-11 stsp }
239 6d9d28c3 2018-03-11 stsp
240 ef99fdb1 2018-03-11 stsp fd = open(path_fileindex, O_RDWR | O_NOFOLLOW, GOT_DEFAULT_FILE_MODE);
241 6d9d28c3 2018-03-11 stsp if (fd == -1) {
242 ef99fdb1 2018-03-11 stsp err = got_error_from_errno();
243 ef99fdb1 2018-03-11 stsp goto done;
244 ef99fdb1 2018-03-11 stsp }
245 ef99fdb1 2018-03-11 stsp if (flock(fd, LOCK_SH | LOCK_NB) == -1) {
246 73a5ef67 2018-03-11 stsp err = (errno == EWOULDBLOCK ? got_error(GOT_ERR_WORKTREE_BUSY)
247 73a5ef67 2018-03-11 stsp : got_error_from_errno());
248 6d9d28c3 2018-03-11 stsp goto done;
249 6d9d28c3 2018-03-11 stsp }
250 6d9d28c3 2018-03-11 stsp
251 6d9d28c3 2018-03-11 stsp err = read_meta_file(&formatstr, gotpath, GOT_WORKTREE_FORMAT);
252 6d9d28c3 2018-03-11 stsp if (err)
253 6d9d28c3 2018-03-11 stsp goto done;
254 6d9d28c3 2018-03-11 stsp
255 6d9d28c3 2018-03-11 stsp version = strtonum(formatstr, 1, INT_MAX, &errstr);
256 6d9d28c3 2018-03-11 stsp if (errstr) {
257 6d9d28c3 2018-03-11 stsp err = got_error(GOT_ERR_WORKTREE_META);
258 6d9d28c3 2018-03-11 stsp goto done;
259 6d9d28c3 2018-03-11 stsp }
260 6d9d28c3 2018-03-11 stsp if (version != GOT_WORKTREE_FORMAT_VERSION) {
261 6d9d28c3 2018-03-11 stsp err = got_error(GOT_ERR_WORKTREE_VERS);
262 6d9d28c3 2018-03-11 stsp goto done;
263 6d9d28c3 2018-03-11 stsp }
264 6d9d28c3 2018-03-11 stsp
265 6d9d28c3 2018-03-11 stsp *worktree = calloc(1, sizeof(**worktree));
266 6d9d28c3 2018-03-11 stsp if (*worktree == NULL) {
267 6d9d28c3 2018-03-11 stsp err = got_error(GOT_ERR_NO_MEM);
268 6d9d28c3 2018-03-11 stsp goto done;
269 6d9d28c3 2018-03-11 stsp }
270 6d9d28c3 2018-03-11 stsp (*worktree)->fd_fileindex = -1;
271 6d9d28c3 2018-03-11 stsp
272 6d9d28c3 2018-03-11 stsp (*worktree)->path_worktree_root = strdup(path);
273 6d9d28c3 2018-03-11 stsp if ((*worktree)->path_worktree_root == NULL) {
274 6d9d28c3 2018-03-11 stsp err = got_error(GOT_ERR_NO_MEM);
275 6d9d28c3 2018-03-11 stsp goto done;
276 6d9d28c3 2018-03-11 stsp }
277 6d9d28c3 2018-03-11 stsp err = read_meta_file(&(*worktree)->path_repo, gotpath,
278 6d9d28c3 2018-03-11 stsp GOT_WORKTREE_REPOSITORY);
279 6d9d28c3 2018-03-11 stsp if (err)
280 6d9d28c3 2018-03-11 stsp goto done;
281 6d9d28c3 2018-03-11 stsp err = read_meta_file(&(*worktree)->path_prefix, gotpath,
282 6d9d28c3 2018-03-11 stsp GOT_WORKTREE_PATH_PREFIX);
283 6d9d28c3 2018-03-11 stsp goto done;
284 6d9d28c3 2018-03-11 stsp
285 6d9d28c3 2018-03-11 stsp done:
286 6d9d28c3 2018-03-11 stsp free(gotpath);
287 6d9d28c3 2018-03-11 stsp free(path_fileindex);
288 6d9d28c3 2018-03-11 stsp if (err) {
289 6d9d28c3 2018-03-11 stsp if (fd != -1)
290 6d9d28c3 2018-03-11 stsp close(fd);
291 6d9d28c3 2018-03-11 stsp if (*worktree != NULL)
292 6d9d28c3 2018-03-11 stsp got_worktree_close(*worktree);
293 6d9d28c3 2018-03-11 stsp *worktree = NULL;
294 6d9d28c3 2018-03-11 stsp } else
295 6d9d28c3 2018-03-11 stsp (*worktree)->fd_fileindex = fd;
296 6d9d28c3 2018-03-11 stsp
297 6d9d28c3 2018-03-11 stsp return err;
298 86c3caaf 2018-03-09 stsp }
299 86c3caaf 2018-03-09 stsp
300 86c3caaf 2018-03-09 stsp void
301 86c3caaf 2018-03-09 stsp got_worktree_close(struct got_worktree *worktree)
302 86c3caaf 2018-03-09 stsp {
303 6d9d28c3 2018-03-11 stsp free(worktree->path_worktree_root);
304 6d9d28c3 2018-03-11 stsp free(worktree->path_repo);
305 6d9d28c3 2018-03-11 stsp free(worktree->path_prefix);
306 6d9d28c3 2018-03-11 stsp if (worktree->fd_fileindex != -1)
307 6d9d28c3 2018-03-11 stsp close(worktree->fd_fileindex);
308 6d9d28c3 2018-03-11 stsp free(worktree);
309 86c3caaf 2018-03-09 stsp }
310 86c3caaf 2018-03-09 stsp
311 86c3caaf 2018-03-09 stsp char *
312 86c3caaf 2018-03-09 stsp got_worktree_get_repo_path(struct got_worktree *worktree)
313 86c3caaf 2018-03-09 stsp {
314 86c3caaf 2018-03-09 stsp return strdup(worktree->path_repo);
315 86c3caaf 2018-03-09 stsp }
316 86c3caaf 2018-03-09 stsp
317 86c3caaf 2018-03-09 stsp struct got_reference *
318 86c3caaf 2018-03-09 stsp got_worktree_get_head(struct got_worktree *worktree)
319 86c3caaf 2018-03-09 stsp {
320 86c3caaf 2018-03-09 stsp return NULL;
321 86c3caaf 2018-03-09 stsp }
322 86c3caaf 2018-03-09 stsp
323 86c3caaf 2018-03-09 stsp const struct got_error *
324 4d94df2d 2018-03-11 stsp got_worktree_change_head(struct got_worktree *worktree, struct got_reference *head,
325 86c3caaf 2018-03-09 stsp struct got_repository *repo)
326 86c3caaf 2018-03-09 stsp {
327 86c3caaf 2018-03-09 stsp return NULL;
328 86c3caaf 2018-03-09 stsp }
329 86c3caaf 2018-03-09 stsp
330 86c3caaf 2018-03-09 stsp const struct got_error *
331 86c3caaf 2018-03-09 stsp got_worktree_checkout_files(struct got_worktree *worktree,
332 86c3caaf 2018-03-09 stsp struct got_repository *repo)
333 86c3caaf 2018-03-09 stsp {
334 86c3caaf 2018-03-09 stsp return NULL;
335 86c3caaf 2018-03-09 stsp }