diff --git a/toys/posix/ls.c b/toys/posix/ls.c index 3e1fad17b444a8b648bdead891a9b28f4c91d5ba..13f916478d8f792f2e9dd565400b2ae393feb3c5 100644 --- a/toys/posix/ls.c +++ b/toys/posix/ls.c @@ -259,6 +259,22 @@ skip: return ret; } +#ifdef TOYBOX_OH_ADAPT +#define ENABLE_HIDDEN_STR "1" +#define ENABLE_HIDDEN_STR_LEN 1 +#define ATTR_VALUE_LEN 8 +int is_file_hidden(const char *path) { + char value[ATTR_VALUE_LEN]; + ssize_t ret = xattr_get(path, "user.filemanager.hidden", &value, sizeof(value) - 1); + if (ret >= 0 && ret < ATTR_VALUE_LEN) { + value[ret] = '\0'; + } else { + value[0] = '\0'; + } + return (ret == ENABLE_HIDDEN_STR_LEN) && !strncmp(ENABLE_HIDDEN_STR, value, sizeof(value)); +} +#endif + // callback from dirtree_recurse() determining how to handle this entry. static int filter(struct dirtree *new) @@ -288,6 +304,19 @@ static int filter(struct dirtree *new) if (FLAG(a)||FLAG(f)) return DIRTREE_SAVE; if (!FLAG(A) && *new->name=='.') return 0; +#ifdef TOYBOX_OH_ADAPT + if (!FLAG(A)) { + char *path = dirtree_path(new, 0); + if (path) { + int is_hidden = is_file_hidden(path); + free(path); + path = NULL; + if (is_hidden) { + return 0; + } + } + } +#endif return dirtree_notdotdot(new) & DIRTREE_SAVE; }