Commit Graph

203 Commits

Author SHA1 Message Date
Matthias Beyer e3db947e68 Add Entry::set_content()
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2019-10-26 16:24:02 +02:00
Matthias Beyer 2a407d161b Add some debug output
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2019-10-26 09:57:05 +02:00
Matthias Beyer 7348378a96 Fix test: Check whether in cache, then get, then check again
After moving an entry, the entry should _not_ be in the cache. This is
just a decision that has to be made, whether we cache the moved entry or
not. I decided to not cache because it is results in less code.

After that check, we get the entry from the backend and then we can
check whether the entry is in the cache, which is then should be.

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2019-10-26 09:57:05 +02:00
Matthias Beyer 583f972788 Add test: Test moving entry with writing to it before and after moving
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2019-10-26 09:57:05 +02:00
Matthias Beyer d1078590c7 Fix: Testing backend bug where an entry was not properly rewritten
When moving an entry, what we did is copying the entry inside the
backend abstraction (the hashmap) from one key to another.

But as the entry itself does also encode its location, we actually have
to rewrite the entire entry. This patch fixes this.

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2019-10-26 09:57:05 +02:00
Matthias Beyer a07e03a25c Fix: Renaming entries should also remove the old entry
This is a bugfix for a bug in Store::move_entry_by_id():
The old entry was not removed after the new one was created.

The bug is a bit subtle. The issue was, that the internal cache held
open a reference to the old entry (as StoreEntry object) and when that
object got drop()ed, the contents of the entry were written to disk,
which resulted in the old entry being recreated.

This patch rewrites the function to behave well. The most critical part
is that we do not check whether the old entry is borrowed with
`hsmap.get()` but rather `hsmap.remove()`. The trick here is that the
`StoreEntry` object is dropped in the moment the check is done, clearing
the cached object and flushing it to the backend (the disk).
After that, we continue doing the filesystem operation and the cache is
clean.

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2019-10-26 09:57:05 +02:00
Matthias Beyer 07f949056e Update dependency: env_logger: 0.6.1 -> 0.7
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2019-10-07 18:18:28 +02:00
Matthias Beyer 87f2a0cb75 Add Tests for Entries::{find_by_id_substr, find_by_id_startswith} 2019-09-01 13:36:39 +02:00
Matthias Beyer 84135b1961 Add Entries::{find_by_id_substr, find_by_id_startswith}
This patch adds functions to the Entries type which can be used for
filtering by id, either with `contains()` or `starts_with()`.

This is useful for the end-user functionality where the user specifies
the ID of an entry only partially.

The implementation still iterates over all entries. This could be
improved, of course, by implementing a `find`-like function on `Store`
directly. But for now, this is good enough.

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2019-09-01 13:36:39 +02:00
flip1995 b2997517bb [No-auto] lib/core/store: Fix Clippy warnings
Signed-off-by: flip1995 <hello@philkrones.com>
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2019-08-28 18:18:41 +02:00
Matthias Beyer 605b98276d Run "cargo fix --all-features" in root of project
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2019-08-25 12:17:07 +02:00
Matthias Beyer 2185d44011 Update all dependencies
This patch updates all dependencies but not "nom".

Done with `cargo upgrade --all` and manual editing.

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2019-06-30 16:44:23 +02:00
Matthias Beyer a7d53e47d1 Update toml-query to 0.9.0
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2019-05-29 18:39:25 +02:00
Matthias Beyer 1482f70320 Update dependency: toml: 0.4 -> 0.5
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2019-05-29 18:39:25 +02:00
Matthias Beyer 5c8af4460e Fix: Entries::in_collection() should be able to return error
This patch changes the Entries::in_collection() interface to return a
Result<()>. This is needed because the fs backend implementation should
be able to check whether a directory actually exists whenever we change
the iterator.

If the implementation detects that the directory does not exist, we can
fail early and error out.

All usages of the interface are adapted by the patch as well.

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2019-05-18 13:37:46 +02:00
Matthias Beyer 112a2d6af8 Add more context in error messages
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2019-05-18 00:53:40 +02:00
Matthias Beyer 1d89844613 Run 'cargo fix' for rust-2018
With this patch we move the codebase to Rust-2018.

The diff was generated by executing

    cargo fix --all --all-features --edition

on the codebase.

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2019-05-18 00:20:59 +02:00
Matthias Beyer 0283c3af7a Merge branch 'fix-path-iterator' into master-ff
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2019-04-13 23:42:20 +02:00
Matthias Beyer 526885ee19 Fix: PathIterBuilder should not yield directories
PathIterBuilder should yield iterator that does only yield file pathes,
not directories.

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2019-04-13 23:00:06 +02:00
Matthias Beyer cb4d5367e4 Rewrite all usages of ModuleEntryPath
Because the code was so complex before, we had to create an object and
then cast that object into a `StoreId` rather than just creating a
`StoreId` object right away.

With this patch, we're using the code-generation approach to generate a
function that creates a `StoreId` object based on the name of the
current module. That's way easier and error handling was also improved
by the switch to the new implementation.

The patch also includes a rewrite of all usages of ModuleEntryPath and
changes them to `module_path::new_id()` calls.

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2019-04-13 22:39:39 +02:00
Matthias Beyer 34d9f3429f Add debug output
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2019-02-20 14:43:29 +01:00
Matthias Beyer 37bf2ce191 Fix: Use StoreIdWithBase::from_full_path
We iterate over full pathes to store entries here, which causes
`StoreId::new()` to error. But if we use the internal parsing helper
`StoreIdWithBase::from_full_path()` and then call `::into_storeid()` on
the resulting object, everything is fine.

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2019-02-20 12:31:37 +01:00
Matthias Beyer 6fd2c9b958 Remove irrelevant tests
Because StoreId objects do not contain bases anymore, we do not need
these tests anymore.

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2019-02-15 22:10:49 +01:00
Matthias Beyer 0888e4345c Use StoreId::local_display_string() for less errorhandling here
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2019-02-15 20:53:29 +01:00
Matthias Beyer 83415e78b9 Adapt to new libimagstore::iter::Entries API
Use Entries::into_storeid_iter() for transforming iterator into right
type.

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2019-02-15 20:53:29 +01:00
Matthias Beyer b4f401675e Add Entries::into_storeid_iter()
This is a more complicated functionality (implementation-wise) of the
`Entries` iterator, which allows a callee to transform it into a
`StoreIdIterator`.

It uses the crate internal `PathIterator` type and a function to extract
the internals of that iterator which is then turned into an iterator
over `Result<StoreId>`, which can be used to build a `StoreIdIterator`.

The implementation is ugly, but we need to be able to transform a
`Entries` iterator into a `StoreIdIterator` in the
`libimagentryannotation`, and possibly in more cases where we want to be
agnostic over iterators.

Maybe there is a cleaner solution to this, hence the comment about
whether this should be removed.

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2019-02-15 20:53:29 +01:00
Matthias Beyer b66371f79b Rewrite Store::new* API: libimagstore does not export backend types
With this change applied, libimagstore does not export backend
representing types anymore.

This change is necessar because when we want to switch the `StoreId`
implementation from "complex and stateful" to "Stateless and Cow<'_,
&str>", we need to be able to have a type which represents a "`StoreId`
plus the path of the Store itself".
This "the path of the Store itself" is passed around as reference, to
minimize runtime impact.

Because such a type should not be exported by the libimagstore crate, we
make it `pub(crate)` internally. But because the backend APIs also have
to use this type, we would export the (private) type in the APIs of the
backend.

Because of that we make the backend API also non-visible to crate users,
which also decreases the surface of the libimagstore API itself.

Besides:
Remove function `Link::with_base()` which is not needed anymore (was
used in tests only).

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2019-02-15 20:53:28 +01:00
Matthias Beyer 35a500f91c Delete unused code
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2019-02-15 20:53:28 +01:00
Matthias Beyer 04a8c5f721 Move to simpler implementation of Storeid
This changes the implementation of the StoreId type to be less complex.
Before we always had to re-attach the path of the store itself each time
a StoreId object was passed to the store. Now we do not do this anymore,
hopefully we can move to a implementation of the Store API which takes
references of StoreId objects in the future.

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2019-02-15 20:53:28 +01:00
Matthias Beyer 45cb122f53 Add debug output
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2019-02-15 19:05:09 +01:00
Matthias Beyer 0916c92a18 Bugfix: Rebuild iterator when changing collection
This patch fixes a bug where the following code (here pseudocode) did
the wrong thing:

    store.entries().in_collection("foo").for_each(||...)

because the `.in_collection()` call for the underlying PathIterator
object did not actually re-build the iterator. It only changed the
contained `PathIterBuilder`, but did not call `.build_iter()` on it to
rebuild the iterator object.

The test added with this patch checks whether the iterator does the
right thing.

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2019-02-15 18:29:15 +01:00
Matthias Beyer 9185abcfa5 Update copyright years
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2019-01-03 18:41:36 +01:00
Matthias Beyer 4fe7fd366c Add Store::exists() for checking whether a StoreId exists as Entry
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2018-12-13 22:49:33 +01:00
Matthias Beyer d70a97191c Simplify Display impl for Storeid 2018-11-26 18:21:28 +01:00
Matthias Beyer dd388e53bb Reimplement StoreId::to_str() without erroring
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2018-11-26 18:15:08 +01:00
Matthias Beyer 9fca66aa89 Forbid unsafe code in all crates 2018-11-11 13:05:55 +01:00
Matthias Beyer 4e516ee19d Update version strings
...for the next release, which will be imag 0.10.0!

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2018-11-10 11:56:37 +01:00
Matthias Beyer 17d4123898 Update dependencies from git versions to proper versions.
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2018-11-09 22:14:11 +01:00
Matthias Beyer 1a70c523dc Remove indirection
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2018-11-06 19:03:19 +01:00
Matthias Beyer d493b04555 Remove scope for better readability
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2018-11-06 19:03:10 +01:00
Matthias Beyer 0e4cb59772 Format code
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2018-11-06 19:02:57 +01:00
Matthias Beyer 582fd10acb FS backend: Safe allocation of new PathBuf object
::stf::fs::create_dir_all() takes any ref to `Path`, which is what we
have here, so we can leave out the allocation of a new PathBuf object
here.

Also remove the match by a `if let Some(_)`, which increases the
readability a bit.

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2018-11-06 18:37:53 +01:00
Matthias Beyer 88a4eee087 Adapt Store::get()/Store::create() to check cache before FS
With this change, the cache is tested before accessing the filesystem,
which probably increases the speed if the cache has the entry, because
we avoid the slow IO operation.

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2018-11-06 18:35:17 +01:00
Matthias Beyer becfcd4180 Fix: In-Memory test backend: Actually remove the old entry on "move"
This fixes a really ugly bug where the in-memory backend for the store
did not remove the entry from the in-memory hashmap on "move", but
simply copied it from the old location to the new one.

That caused tests to fail after the fixes introduced for the
Store::get() function which checked the filesystem and the internal
cache whether an entry exists before the actual "get" operation, because
an old entry would still exist after a move (only in the testcases).

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
Fixes: 09e8619cf5 ("libimagstore: Move from error-chain to failure")
2018-11-06 18:34:33 +01:00
Matthias Beyer daaa4fd9ca Make assert!() output more verbose
By printing the actual `Result<>` object that failed the assertion.

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2018-11-06 18:17:46 +01:00
Matthias Beyer d982a657f8 Rewrite Debug for FileLockEntry
This changes the implementation of Debug for the FileLockEntry to be
more explanatory of how the entry actually looks like. It does not only
print the path of the store anymore, but also the location of the Entry.

Printing header and content would be still too much, tho.

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2018-11-06 18:12:58 +01:00
Matthias Beyer e919435504 Fix: Remove call to deprecated function 2018-11-06 14:48:49 +01:00
Matthias Beyer cb0fcaffde Remove logging calls in favour of debug calls
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2018-11-01 21:35:40 +01:00
Matthias Beyer f01a262bdf Add debugging output in test via logger 2018-11-01 20:37:00 +01:00
Matthias Beyer 3bf3a8890b Add debugging output in test via logger 2018-11-01 20:36:46 +01:00