Skip to content

Commit 13954b8

Browse files
Changed!: Do not show files as shortcuts that are broken symlinks or their canonical path is not under the ~/.shortcuts directory
Validation of shortcut file was already being done before execution by 32f344e.
1 parent 15b3698 commit 13954b8

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

app/src/main/java/com/termux/widget/TermuxWidgetService.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import android.widget.RemoteViews;
66
import android.widget.RemoteViewsService;
77

8+
import com.termux.shared.file.FileUtils;
89
import com.termux.shared.termux.TermuxConstants;
910
import com.termux.shared.termux.TermuxConstants.TERMUX_WIDGET.TERMUX_WIDGET_PROVIDER;
1011

@@ -18,8 +19,16 @@ public final class TermuxWidgetService extends RemoteViewsService {
1819

1920
public static final FileFilter SHORTCUT_FILES_FILTER = new FileFilter() {
2021
public boolean accept(File file) {
22+
// Do not show hidden files starting with a dot.
2123
if (file.getName().startsWith("."))
2224
return false;
25+
// Do not show broken symlinks
26+
else if (!FileUtils.fileExists(file.getAbsolutePath(), true))
27+
return false;
28+
// Do not show files that are not under TermuxConstants#TERMUX_SHORTCUT_SCRIPTS_DIR_PATH
29+
else if (!FileUtils.isPathInDirPath(file.getAbsolutePath(), TermuxConstants.TERMUX_SHORTCUT_SCRIPTS_DIR_PATH, true))
30+
return false;
31+
// Do not show files under TermuxConstants.TERMUX_SHORTCUT_SCRIPT_ICONS_DIR_PATH
2332
else if (TermuxConstants.TERMUX_SHORTCUT_SCRIPTS_DIR.equals(file.getParentFile()) &&
2433
file.getName().equals(TermuxConstants.TERMUX_SHORTCUT_SCRIPT_ICONS_DIR_BASENAME))
2534
return false;

0 commit comments

Comments
 (0)