Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@Eutalix
Copy link

@Eutalix Eutalix commented Nov 26, 2025

Motivation

Many external editors and file managers (such as ZArchiver, QuickEdit, Acode, etc.) fail to save modifications to files stored in Termux when accessing them via SAF (Storage Access Framework).

This happens because many of these apps rely on an "atomic write" strategy (write to temp file -> delete original -> rename temp to original). Since TermuxDocumentsProvider was not advertising FLAG_SUPPORTS_RENAME nor implementing the renameDocument method, these operations failed silently or were disabled in the client apps.

Changes

  1. Implemented renameDocument: Added the required logic to rename files using File.renameTo, including checks for destination existence.
  2. Fixed Capability Flags: Updated includeFile to correctly advertise FLAG_SUPPORTS_RENAME and FLAG_SUPPORTS_DELETE when the parent directory is writable.
  3. NPE Fix: Added a null check for file.getParentFile() in includeFile to prevent a potential crash when querying root directories.
  4. Improved createDocument: Refactored file creation to correctly use new File(parent, name) instead of potentially unsafe path concatenation.

Testing

I verified the logic against Android DocumentsContract specifications.
Note: Due to current environment limitations (coding directly on mobile), I was unable to build the full Termux APK locally. However, these changes are standard implementation requirements for fully compliant DocumentProviders.

Adds support for file renaming through the Storage Access Framework.\n\nThis implements the renameDocument method and adds the FLAG_SUPPORTS_RENAME, enabling full read/write functionality for SAF clients like Acode that rely on rename for their save operations.
gjr1130-crypto

This comment was marked as spam.

bretthowell714-source

This comment was marked as spam.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants