Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Template directory on read-only filesystem makes cordova crash #588

Open
3 tasks done
Ekleog opened this issue Nov 20, 2022 · 8 comments
Open
3 tasks done

Template directory on read-only filesystem makes cordova crash #588

Ekleog opened this issue Nov 20, 2022 · 8 comments

Comments

@Ekleog
Copy link

Ekleog commented Nov 20, 2022

Hey! I've been trying to use cordova for a few hours, and am hitting a small issue.

Anyway, thank you for all the work you put into it!

Bug Report

Problem

What is expected to happen?

If the template directory of cordova is on a read-only filesystem, I expect cordova create or cordova platform add to work and chmod the files so that they become read-writable by me

What does actually happen?

Instead, cordova doesn't chmod the files, then tries to write to them and errors out.

Information

I'm using NixOS, and this is the reason why my template directory is on a read-only filesystem: cordova as a whole is on a read-only filesystem. So the reproducer will be using nix, that can that said be installed on other OSes too.

This is easy to work around for cordova create, but cordova platform add is a bit harder to work around. The repro is also more complex so I'm not writing it down, but it should be the same fix anyway: after copying from a template directory cordova would need to chmod u+w the files

Command or Code

Reproducer:

[/tmp]$ nix-shell -I channel:nixos-unstable -p nodePackages.cordova
[nix-shell:/tmp]$ cordova create test
Creating a new cordova project.
EACCES: permission denied, open '/tmp/test/config.xml'

Environment, Platform, Device

Running cordova create on NixOS.

Version information

Cordova CLI 11.0.0

Checklist

  • I searched for existing GitHub issues
  • I updated all Cordova tooling to most recent version
  • I included all the necessary information above
@breautek
Copy link
Contributor

If I understand it correctly, in you're environment you effectively have umask set to something restrictive, like read-only, so when cordova creates a new directory, by default it only has readonly permissions. Is that correct?

I think we could probably check and attempt to ensure that the directory permissions it creates have write access instead of assuming, but Cordova also relies on a lot of third-party tooling, like the Android SDK/Gradle, etc. So I'm not sure far that will go.

For example, Gradle also fails installing the wrapper in this kind of environment:

  • What went wrong:
    Gradle could not start your build.
    Could not create service of type BuildLifecycleAwareVirtualFileSystem using GradleUserHomeServices.createVirtualFileSystem().
    java.io.FileNotFoundException: /home/norman/.gradle/.tmp/gradle_fs_probing9830715162890560142.tmp (Permission denied)

So read-only filesystems is not something we can reasonably support because third-party tooling also doesn't support this kind of environments.

@breautek breautek closed this as not planned Won't fix, can't repro, duplicate, stale Nov 21, 2022
@Ekleog
Copy link
Author

Ekleog commented Nov 24, 2022

Sorry for mis-explaining! This is not a umask issue, just that the cordova template repository is u-w.

So, as cordova basically does cp -R $templatedir $outdir (here for cordova create, though I haven't checked where for cordova platform add), it carries over the u-w permission that was on the template files (but not on umask or anything), and then fails for further changes.

I would definitely not expect umask u-w situations to work with cordova, but I do think cordova also adding the write permission for the user before trying to change files would work. At least I can say that after manually fixing up the copied template permissions, everything else seems to work fine :)

@breautek
Copy link
Contributor

breautek commented Nov 24, 2022

Ok, I still don't quite understand though. The template repository is found at https://github.com/apache/cordova-app-hello-world

All the files appear to have owner R/W, group R/W, and world Read permissions, which I think should be sufficient? If you have a solution though, feel free to make a PR.

@breautek breautek reopened this Nov 24, 2022
@Ekleog
Copy link
Author

Ekleog commented Dec 3, 2022

TL;DR: I'm installing cordova from my package manager, which fetches the cordova repository and stores it on a filesystem where all files are 0444 (or 0555 depending on the file type). This is why just a recursive-copy doesn't work. The only solution I can think of would be to do a recursive chmod u+w just between the copy and editing the files.

I'm willing to open a PR with it, but seeing it's the same solution as it'd be for umask that you close… I'd just like to check that it sounds like a reasonable idea to you? (before I learn node to make it, as I've literally never developed in node yet, I'm using cordova to compile a rust wasm app to android, so it'd take me quite a while if it's for the PR to just be closed)

Slightly-longer explanation for why cordova is on a chmod 0444 filesystem: I'm using NixOS, which does not respect FHS to provide features that are off-topic here but can be found on the internet. As such, binaries basically do not work well off the upstream package managers, including npm. So I'm using a tool that converts cordova's npm package into a nix package to be able to use it; but then nix package must live on that 0444 filesystem (because it's part of nix's design, required to provide said features)

@breautek
Copy link
Contributor

breautek commented Dec 3, 2022

My concern is the template is only one cog of the machine.... We utilise several third-party tooling that also creates directories and file structures. Like the Android SDK uses Gradle as it's main build tool and Gradle projects installs a local gradle wrapper. These tools also generates folder structures and if they work in your environment as is, then awesome... but if they do not work, then that's a problem that cannot be solved by Cordova, even if we solve the problem with the Cordova app template.

For example, if you create a folder and add the following files:

settings.gradle

rootProject.name = 'gradletest'

build.gradle

// Can be left empty

Then run gradle wrapper, does gradle successfully installs the wrapper?

To be clear, I don't necessary oppose any solutions to fix the template installation, but that only solves one build step. If it fails on another build step, particularly one controlled by third-party tooling like the Android SDK, then the effort of fixing the template installation is kind of wasted.

@Ekleog
Copy link
Author

Ekleog commented Dec 3, 2022

Well, I have no idea what that's supposed to do, but I get the following result:

$ gradle wrapper
Starting a Gradle Daemon (subsequent builds will be faster)

BUILD SUCCESSFUL in 9s
1 actionable task: 1 executed
$ ls
build.gradle  gradle  gradlew  gradlew.bat  settings.gradle

So I guess it works fine?

That said, it's definitely possible that other things would break down the line, but at least all the commands except for the template-generating ones of cordova currently seem to work fine on my computer, if I just manually write the template contents :)

@breautek
Copy link
Contributor

breautek commented Dec 3, 2022

Well, I have no idea what that's supposed to do, but I get the following result:

It installs the gradle wrapper. I have been assuming you're potentially working with an Android project, in which case Cordova will effectively do this kind of build step eventually. But yes, it appeared to install the gradle wrapper fine, which looks promising.

I'm not 100% sure where you need to add the changes to change the permissions, the template files themselves can be found at https://github.com/apache/cordova-app-hello-world but the installing of the template is likely handled by another package... I think https://github.com/apache/cordova-create

before I learn node to make it, as I've literally never developed in node yet,

There is a chmod Node API, but it might be cumbersome to use since I think we need to recursively change the permission of the entire template directory structure + it's files. I'm linking Node 14 docs because Cordova still supports Node 14, so have to ensure we don't use any features added later.

If you have questions about developing the PR, you can try asking our Slack community, or the Dev Mailing List. Of course you can also ask me but I'm not super familiar with that part of the codebase.

Feel free to ping me/request me for review if you manage to develop a PR.

@Ekleog
Copy link
Author

Ekleog commented Dec 6, 2022

Got it thanks! I'll do when I manage to get a PR done :)

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

No branches or pull requests

2 participants