Refreshing a snap package when not using the default home directory does not transfer save data between revisions

Bug #2033871 reported by Ghadi Rahme
10
This bug affects 1 person
Affects Status Importance Assigned to Milestone
snapd
Confirmed
High
Ghadi Rahme

Bug Description

[Description]

When the home directory is not /home, snaps who refresh will fail to copy the data from one revision to another. For example lets say the home directory is in /home/canonical. The snap home data directory for user1 would be in /home/canonical/user1/snap. If a snap installed called "mysnap" refreshes and moves from revision 1 to revision 2, the data in /home/canonical/user1/snap/mysnap/1 is not copied into /home/canonical/user1/snap/mysnap/2 which means that the user when launching the snap will essentially be greeted with the equivalent of a fresh install since none of his saved data is present. For applications like WICKR it means the user has to login again every time the snap updates.
It is important to note that this issue occurs even when running "sudo snap set system homedirs=/home/canonical/" to define the new home directory location.

[Steps to Reproduce]

Thank you to @fabio.martins for setting up a test snap as well as providing the instructions.

1. Create a new user with a different home directory (I this example I will use user user1 and the home directory will be /home/canonical)
2. Run the following command: $ sudo snap set system homedirs=/home/canonical
3. Install the test snap using the command: $ sudo snap install fabiomirmartestsnap --beta
4. Run the snap with the command: $ fabiomirmartestsnap.aws-os-partners-testing
5. Inside /home/canonical/user1/snap/fabiomirmartestsnap you should see a folder named "1" representing the revision we just installed. It contains a text file called "output.txt"
6. Print the content of the output.txt file: $ cat /home/canonical/user1/snap/fabiomirmartestsnap/current/output.txt
It should display the line "Test 1 complete"
7. Now refresh the snap to a new revision: $ sudo snap refresh fabiomirmartestsnap --channel edge
8. Run the snap again: $ fabiomirmartestsnap.aws-os-partners-testing
9. Now you should also have a folder named "3" representing the newly installed revision.
10. Print the content of output.txt: $ cat /home/canonical/user1/snap/fabiomirmartestsnap/current/output.txt
It will show "Test 2 complete" and not contain the original line "Test 1 complete"

By printing the output.txt file inside "1" we can see that it still contains the original line "Test 1 complete" but when doing the same inside "3" we only have the newly written line "Test 2 complete"

[Expected Behavior]

The expected behavior would be to have output.txt inside "3" have the following content:
   Test 1 complete
   Test 2 complete

Instead we have:
   Test 2 complete

[Solution]

I have written a patch to fix the issue using the latest master branch of snapd, however it seems there is an issue with the master branch at the moment of writing this since it refuses to run any snap application (even without my modification). I have back-ported my changes to the 2.59.5 branch and can confirm that I was successful in resolving the issue. My patch still needs some work to adapt some of the golang test scripts but I will open a PR when it is ready.

This issue is currently affecting AWS, they reported not only this issue but a similar one as well where the snap application data is not deleted when removing the snap using the same setup. My patch fixes both issues.

Changed in snapd:
assignee: nobody → Ghadi Rahme (ghadi-rahme)
description: updated
Revision history for this message
Ghadi Rahme (ghadi-rahme) wrote :
description: updated
Revision history for this message
Sergio Cazzolato (sergio-j-cazzolato) wrote :

Thanks for raising and working on fixing it.

Changed in snapd:
status: New → Confirmed
importance: Undecided → High
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.