Insufficent rights for npm install in Termux on Android


Question

I'm trying to install a Node.js module in a folder, for example, /data/data/com.termux/files/home/storage/shared/documents/projects/code/js/test-npm, from Termux on rooted Android 6 running npm install. Installation starts, but never succeeds, throwing errors and warnings like npm ERR! cb() never called! and WARN tar EPERM: operation not permitted, futime.



Which permissions should I grant to npm and how?



Update 1: tried running npm install in /storage/emulated/0/Documents/projects/code/js/test-npm, got the same errors. Termux has Storage access permission in Android installed apps manager.


Answer

WARN tar EPERM: operation not permitted, futime indicates that futime syscall (used to change file last access and modification times) fails with error: EPERM. From utime manpage 1:




EPERM ... the caller's effective UID does not match the owner of the file ...




That seems to be the reason of failure. You are using path: /data/data/com.termux/files/home/storage/shared/ which is actually /sdcard/ 2 (symlink to /storage/emulated/0/). It's not an actual filesystem but an emulated 3 view of underlying filesystem (ext4 or f2fs). It has fixed permissions and doesn't support many features of Linux filesystems including symlinks and ioctls like FS_IOC_FIEMAP 4.



Due to fixed permissions all directories and files in /sdcard/ are always owned by user root (UID 0). So while trying to change file's timestamp, Operation not permitted is returned. touch command however uses utimensat 5 which has different permissions requirements.



So to avoid this problem, you should not use emulated filesystem. Termux $HOME directory is on ext4 or f2fs, so it's a good place to save files. Use e.g. /data/data/com.termux/files/home/npm-test directory.



From comments:




But is it possible to somehow create a link inside $HOME to another location, which will grant all the rights that Termux has for $HOME for all the subfolders of this distant location?




No it's not possible on non-rooted phone. Apps can write only to their private directories in internal storage (which is /data/data/com.termux for Termux) and in shared storage (/sdcard/Android/data/com.termux). Apps with Storage permission granted can read and write to whole /sdcard/. There is no other place on device where apps can save files 6. With SELinux disabled or permissive, it's possible to write to a sub-directory created (with adb shell) in /data/local/tmp, but it's not intended use of this directory.






LINKS:



1 utime manpage

2 How do I access $HOME/storage outside of Termux (with a file explorer)?

3 What is /storage/emulated/0/?

4 How can I make a symlink inside /storage/emulated/0?

5 How to change the modified date of a file without root?

6 Where Android apps store data?


Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes