-
-
Notifications
You must be signed in to change notification settings - Fork 5
multi-directory backup support #200
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
Open
mlapaglia
wants to merge
21
commits into
develop
Choose a base branch
from
multi-directory
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
2a2e5cb
first try
mlapaglia da78ab7
lint
mlapaglia e9ee415
fixes and tests
mlapaglia 9867ad1
organization, lint
mlapaglia 13299ff
DRYNESS
mlapaglia c390551
better filepath handling
mlapaglia 3d8f3d3
absolute path checks
mlapaglia 2bcf30f
source path fix
mlapaglia a1071f1
Merge branch 'develop' into multi-directory
mlapaglia 93d3cff
MERGE
mlapaglia cd15f43
make it a modal
mlapaglia a78f336
use json not form data
mlapaglia 6c6d0a8
clear this out after creating/saving
mlapaglia acac83c
lint
mlapaglia d018e87
convert to source paths everywhere
mlapaglia 51c5d79
add some e2e tests
mlapaglia aac4451
create new column don't rename old one
mlapaglia 8f1f265
lint
mlapaglia 7399cae
test fixes
mlapaglia d0e92c4
Merge branch 'develop' into multi-directory
mlapaglia 656092d
Merge branch 'develop' into multi-directory
mlapaglia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/borgitory/templates/partials/schedules/source_path_field.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| <!-- Individual Source Path Field --> | ||
| <div class="flex items-start gap-2 source-path-entry"> | ||
| <div class="flex-1"> | ||
| {% set input_id = "source-path-" ~ index %} | ||
| {% set input_name = "source_paths" %} | ||
| {% set input_value = path_value if path_value is defined else "" %} | ||
| {% set placeholder = "/path/to/data" %} | ||
| {% set required = false %} | ||
| {% include "partials/shared/path_autocomplete.html" %} | ||
| </div> | ||
| {% if show_remove %} | ||
| <button type="button" | ||
| class="mt-1 text-red-600 hover:text-red-800 dark:text-red-400 dark:hover:text-red-300 p-2 rounded-md hover:bg-red-50 dark:hover:bg-red-900/20 transition-colors flex-shrink-0" | ||
| hx-post="/api/schedules/source-paths/remove-field" | ||
| hx-include="closest form" | ||
| hx-vals='{"remove_index": {{ index }}}' | ||
| hx-target="#source-paths-container" | ||
| hx-swap="innerHTML" | ||
| title="Remove source path"> | ||
| <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"> | ||
| <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"> | ||
| </path> | ||
| </svg> | ||
| </button> | ||
| {% endif %} | ||
| </div> |
19 changes: 19 additions & 0 deletions
19
src/borgitory/templates/partials/schedules/source_paths_container.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| <!-- Source Paths Container --> | ||
| <div class="space-y-2" id="source-paths-fields"> | ||
| {% for path_value in source_paths %} | ||
| {% set index = loop.index0 %} | ||
| {% set show_remove = source_paths | length > 1 %} | ||
| {% include "partials/schedules/source_path_field.html" with context %} | ||
| {% endfor %} | ||
| </div> | ||
| <button type="button" | ||
| class="mt-2 text-sm text-blue-600 hover:text-blue-800 dark:text-blue-400 dark:hover:text-blue-200 font-medium flex items-center gap-1" | ||
| hx-post="/api/schedules/source-paths/add-field" | ||
| hx-include="closest form" | ||
| hx-target="#source-paths-container" | ||
| hx-swap="innerHTML"> | ||
| <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"> | ||
| <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 6v6m0 0v6m0-6h6m-6 0H6"></path> | ||
| </svg> | ||
| Add Source Path | ||
| </button> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| """Utilities for handling multiple source paths stored as JSON array strings.""" | ||
|
|
||
| import json | ||
| from typing import List | ||
|
|
||
|
|
||
| def parse_source_paths(source_path: str) -> List[str]: | ||
| """Parse a source_path value into a list of paths. | ||
|
|
||
| Handles both legacy single-path strings and JSON array strings. | ||
| """ | ||
| if not source_path or not source_path.strip(): | ||
| return [] | ||
|
|
||
| stripped = source_path.strip() | ||
| if stripped.startswith("["): | ||
| try: | ||
| parsed = json.loads(stripped) | ||
| if isinstance(parsed, list): | ||
| return [p for p in parsed if isinstance(p, str) and p.strip()] | ||
| return [stripped] | ||
| except (json.JSONDecodeError, ValueError): | ||
| return [stripped] | ||
|
|
||
| return [stripped] | ||
|
mlapaglia marked this conversation as resolved.
Outdated
|
||
|
|
||
|
|
||
| def serialize_source_paths(paths: List[str]) -> str: | ||
| """Convert a list of paths to a JSON array string for storage.""" | ||
| cleaned = [p.strip() for p in paths if p and p.strip()] | ||
| if not cleaned: | ||
| return "[]" | ||
| return json.dumps(cleaned) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| """Tests for source_paths utility functions.""" | ||
|
|
||
| import json | ||
| from borgitory.utils.source_paths import parse_source_paths, serialize_source_paths | ||
|
|
||
|
|
||
| class TestParseSourcePaths: | ||
| def test_single_plain_path(self): | ||
| assert parse_source_paths("/data") == ["/data"] | ||
|
|
||
| def test_single_path_json_array(self): | ||
| assert parse_source_paths('["/data"]') == ["/data"] | ||
|
|
||
| def test_multiple_paths_json_array(self): | ||
| result = parse_source_paths('["/home/user/src", "/home/user/Documents"]') | ||
| assert result == ["/home/user/src", "/home/user/Documents"] | ||
|
|
||
| def test_empty_string(self): | ||
| assert parse_source_paths("") == [] | ||
|
|
||
| def test_whitespace_only(self): | ||
| assert parse_source_paths(" ") == [] | ||
|
|
||
| def test_empty_json_array(self): | ||
| assert parse_source_paths("[]") == [] | ||
|
|
||
| def test_strips_whitespace_from_input(self): | ||
| assert parse_source_paths(" /data ") == ["/data"] | ||
|
|
||
| def test_filters_empty_strings_in_array(self): | ||
| assert parse_source_paths('["/data", "", " "]') == ["/data"] | ||
|
|
||
| def test_invalid_json_starting_with_bracket(self): | ||
| assert parse_source_paths("[not json") == ["[not json"] | ||
|
|
||
| def test_json_array_with_non_string_elements(self): | ||
| assert parse_source_paths('["/data", 123]') == ["/data"] | ||
|
|
||
| def test_legacy_path_with_spaces(self): | ||
| assert parse_source_paths("/path/with spaces/data") == ["/path/with spaces/data"] | ||
|
|
||
| def test_three_paths(self): | ||
| paths = '["/appdata/app1", "/appdata/app2", "/appdata/app3"]' | ||
| result = parse_source_paths(paths) | ||
| assert result == ["/appdata/app1", "/appdata/app2", "/appdata/app3"] | ||
|
|
||
|
|
||
| class TestSerializeSourcePaths: | ||
| def test_single_path(self): | ||
| result = serialize_source_paths(["/data"]) | ||
| assert json.loads(result) == ["/data"] | ||
|
|
||
| def test_multiple_paths(self): | ||
| result = serialize_source_paths(["/src", "/Documents"]) | ||
| assert json.loads(result) == ["/src", "/Documents"] | ||
|
|
||
| def test_empty_list(self): | ||
| assert serialize_source_paths([]) == "[]" | ||
|
|
||
| def test_filters_empty_strings(self): | ||
| result = serialize_source_paths(["/data", "", " "]) | ||
| assert json.loads(result) == ["/data"] | ||
|
|
||
| def test_strips_whitespace(self): | ||
| result = serialize_source_paths([" /data "]) | ||
| assert json.loads(result) == ["/data"] | ||
|
|
||
| def test_roundtrip(self): | ||
| original = ["/home/user/src", "/home/user/Documents", "/backups"] | ||
| serialized = serialize_source_paths(original) | ||
| parsed = parse_source_paths(serialized) | ||
| assert parsed == original |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.