The directory synchronization code grew out of the desire to have a set
of files described by a glob and short, in-memory contents be reflected
to the disk in an efficient and predictable way.
Recently this code has started to be used to install icon themes shipped
by snaps. This means it may be used to coerce snapd to read arbitrary
amount of data into memory.
This address this issue by generalizing the directory sync APIs to take
an interface instead of a concrete representation of the desired file.
There are now three concrete implementations, one that keeps the content
in memory, just like before, called MemoryBlob and two new ones:
FileReference and FileContentReference. Those both refer to an existing
file for content, opening up the possibility to refer to large files.
They only differ in the treatment of file mode, either mirroring the
mode of the file being referred or using a fixed mode, respectively.
Behind the scenes the EnsureFileState function will no longer read all
of the file into memory. Instead if will use FileReference to stream it,
chunk by chunk, in an attempt to see if the file is identical to what we
expected.
On top of that, if the file is not the same and the caller has provided
a FileReference or FileContentReference, the logic that writes a new
file and replaces the original is also using streaming, again saving a
in-memory copy.
This way we can now process files of arbitrary size using fixed amount
of memory. This involves the new icon wrapper which has been switched to
use FileContentReference.
The patch contains some verbose automatic changes around the code using
maps of FileState structure to replace them with maps of FileState
interface instead.
Signed-off-by: Zygmunt Krynicki <me@zygoon.pl>
Unit tests assumed that default snap mount directory is /snap, but did not mock
the distro. Stick to whatever is correct for the host, and use proper paths
instead.
Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
* interfaces: add support for the snapd snap in the dbus backend
When writing the userd service files we only looked at the core
snap so far. However when we transition to the snapd snap we
also need to look there for the right files.
* interfaces: ensure setupDbusServiceForUserd prefers the snapd snap
When both the core and the snapd snap are installed we need to
prefer the snapd snap or the content of the userd service file
will flip-flop.
* interfaces: add comment about racy setupDbusServiceForUserd