Commit Graph

376 Commits

Author SHA1 Message Date
Matthias Beyer 01db294700 Add Runtime::input_is_pipe()
We need this because we might want to check whether we can get the STDIN
handle from the runtime or not.
In some (rare) cases, the runtime "thinks" that STDIN is a stream of
IDs, but it is not. So the client can check whether stdin is a pipe
(thus, whether Runtime thinks that there's a stream of IDs) and easily
work around that by taking ::std::io::stdin() itself.

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2019-11-09 15:51:09 +01:00
Matthias Beyer cc8150e0a9 Add extension trait for iterator over Result<Entry>
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2019-10-27 13:39:34 +01:00
Matthias Beyer 39cf75a532 Add iterator extensions for store-id touched reporting
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2019-10-27 13:39:34 +01:00
Matthias Beyer 106be5746d Revert "Add extension traits for handling Result<Option<T>, E> conversion"
This reverts commit d810b63886f4006d01bca894982bbc867616f37c.

As resiter v0.4.0 does provide this extension now, we don't need it in
the codebase anymore.
2019-10-26 18:16:37 +02:00
Matthias Beyer 0e20b25091 Add extension traits for handling Result<Option<T>, E> conversion
This extension traits help transforming Result<Option<T>, E> to
Result<T, E> or transforming an iterator over the former type to an
iterator over the latter type.

Should be moved to resiter of course, but we need to implement this
first.

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2019-10-26 16:35:31 +02:00
Matthias Beyer 19f6391d8a Implement Error for ExitCode
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2019-10-26 16:35:31 +02:00
Matthias Beyer e3db947e68 Add Entry::set_content()
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2019-10-26 16:24:02 +02:00
Leon Schuermann 7a37c47263 Add ImagApplication trait for CLI completion + single-binary support
To re-add the imag-binary CLI completion, as well as to enable
building a single imag containing all of the subcommands, this commit
introduces an ImagApplication trait to be implemented by all imag
binary crates. The binary crates will be converted to libraries, with
an additional binary target. This enables standalone and single binary
builds.

On its own, this commit doesn't do much, but rather it paves the way
to dynamically interacting with the imag uis/clis using a
library-crate interface.

Signed-off-by: Leon Schuermann <leon@is.currently.online>
2019-10-26 14:41:31 +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 2a23002a07 Fix: --override-config argument can be passed multiple times
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2019-10-13 12:21:57 +02:00
Matthias Beyer 613b78f369 Update dependency: ansi_term: 0.11.0 -> 0.12 2019-10-07 18:18:28 +02:00
Matthias Beyer 5edb470a5f Update dependency: handlebars: 1.1.0 -> 2 2019-10-07 18:18:28 +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
flip1995 7b5f216e01 [No-auto] lib/core/rt: 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
flip1995 c7ac440c92 [Auto] lib/core/rt: Fix Clippy warnings
Signed-off-by: flip1995 <hello@philkrones.com>
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2019-08-28 18:18:40 +02:00
flip1995 f0a734839d [Auto] lib/core/error: Fix Clippy warnings
Signed-off-by: flip1995 <hello@philkrones.com>
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2019-08-28 18:18:40 +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 0d1cfb6b4b Refactor: Do not provide functions for these identifiers
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2019-07-26 23:20:50 +02:00
Matthias Beyer 9c896eb98b Add checks whether variables are valid unicode and propagate appropriate error
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2019-07-25 19:52:49 +02:00
Matthias Beyer 5f10ab976f Rewrite get_rtp_match() to not panic
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2019-07-24 21:32:21 +02:00
Matthias Beyer c09c5b8bad Remove use of Itertools
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2019-06-30 19:27:54 +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 11c2cab916 Allow unused variable here 2019-06-22 12:00:07 +02:00
Matthias Beyer 2268fd8091 Import toml-query with typed feature
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2019-05-31 12:48:00 +02:00
Matthias Beyer 5f5ce54edb Rewrite to use derive macro
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2019-05-30 09:39:22 +02:00
Matthias Beyer a3f771ca65 Add comment why we do this
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2019-05-30 09:32:07 +02:00
Matthias Beyer fb8b50fa9a Remove boilerplate by enabling serde in "log" dependency
This patch adds the "serde" feature to the "log" dependency, so we can
deserialize logging levels directly into "log" types.

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2019-05-30 09:32:07 +02:00
Matthias Beyer 185ec25b9e Rewrite logging config deserialization
This patch rewrites the logging config deserialization. It removes the
manual traversing of the config toml structure and replaces it with
types which implement `Deserialize`, which is way more convenient and
easy to read (and extend).

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2019-05-30 09:32:07 +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
Leon Schuermann ed457495c8 Introduce proper error handling in IdPathProvider
Prior to this change, the IdPathProvider implementation would be
responsible for exiting the process on insufficient / wrong arguments.
However, such error handling should be performed together with the
business logic and not in CLI-parsing related code.

This change introduces a clear separation: both parsing errors and
insufficient id path arguments can now be return from inside the
`get_ids`-method, and get passed up to the application logic to be
handled.

This change is reflected in all instances of IdPathProvider and their
surrounding code.

Signed-off-by: Leon Schuermann <leon.git@is.currently.online>
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2019-05-24 21:03:34 +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 00fa3e7b78 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 de522ec0f2 Fix for rust beta compiler
The beta compiler reports duplicated input:

error: the item `IntoValues` is imported redundantly
   --> lib/entry/libimagentrylink/src/internal.rs:398:13
    |
36  | use self::iter::IntoValues;
    |     ---------------------- the item `IntoValues` is already imported here
...
398 |         use internal::iter::IntoValues;
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^
    |

so we fix this here.

Other imports were fixed as well.

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2019-04-13 22:06:53 +02:00
Matthias Beyer 82a2fa1528 Remove old TODO
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2019-03-09 13:30:12 +01:00
Matthias Beyer 341e64998d Remove Iterator::size_hint() implementation
I'm not sure why the author added this in the first place, but I bet we
don't need this.

So remove code we do not need. Feel free to prove me wrong and revert
this patch.

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2019-03-07 20:53:12 +01: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