don't print .. at sandbox top level

This commit is contained in:
phoebos 2022-07-29 13:06:20 +01:00 committed by Devine Lu Linvega
parent 245ba17115
commit 57dfcdf717
1 changed files with 11 additions and 0 deletions

View File

@ -82,6 +82,17 @@ file_read_dir(UxnFile *c, char *dest, Uint16 len)
Uint16 n; Uint16 n;
if(c->de->d_name[0] == '.' && c->de->d_name[1] == '\0') if(c->de->d_name[0] == '.' && c->de->d_name[1] == '\0')
continue; continue;
if(strcmp(c->de->d_name, "..") == 0) {
/* hide "sandbox/.." */
char cwd[PATH_MAX] = {'\0'}, t[PATH_MAX] = {'\0'};
/* Note there's [currently] no way of chdir()ing from uxn, so $PWD
* is always the sandbox top level. */
getcwd(cwd, sizeof(cwd));
/* We already checked that c->current_filename exists so don't need a wrapper. */
realpath(c->current_filename, t);
if (strcmp(cwd, t) == 0)
continue;
}
if(strlen(c->current_filename) + 1 + strlen(c->de->d_name) < sizeof(pathname)) if(strlen(c->current_filename) + 1 + strlen(c->de->d_name) < sizeof(pathname))
sprintf(pathname, "%s/%s", c->current_filename, c->de->d_name); sprintf(pathname, "%s/%s", c->current_filename, c->de->d_name);
else else