Compare commits
10
Commits
8347445f51
...
1d744ba504
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1d744ba504 | ||
|
|
9277e2a331 | ||
|
|
b6e8e07d78 | ||
|
|
b56c79e5da | ||
|
|
98e001d719 | ||
|
|
8e144b9154 | ||
|
|
c12408d2e3 | ||
|
|
22102cd1ea | ||
|
|
d2a5d36bd2 | ||
|
|
8ae9780c0e |
No files matched your search
@@ -45,7 +45,8 @@ ykanban <path>
|
|||||||
```
|
```
|
||||||
|
|
||||||
- Exactly one argument is accepted. A relative path is resolved against the
|
- Exactly one argument is accepted. A relative path is resolved against the
|
||||||
current working directory, so `ykanban .` opens the current folder.
|
current working directory, so `ykanban .` opens the current folder (but see
|
||||||
|
[macOS](#macos) when starting through `open`).
|
||||||
- YKanBan looks for `.ykanban` **only in `<path>` itself**; it does not search
|
- YKanBan looks for `.ykanban` **only in `<path>` itself**; it does not search
|
||||||
parent folders the way Git does.
|
parent folders the way Git does.
|
||||||
- There are no command-line options. An argument starting with `-` is never
|
- There are no command-line options. An argument starting with `-` is never
|
||||||
@@ -57,11 +58,11 @@ instead:
|
|||||||
|
|
||||||
| Page | When |
|
| Page | When |
|
||||||
|---|---|
|
|---|---|
|
||||||
| Invalid arguments | No argument, more than one argument, an empty argument, or an argument starting with `-` (including `--help`). Shows the usage line. |
|
| Invalid arguments | No argument, more than one argument, an empty or whitespace-only argument, an argument starting with `-` (including `--help`), or a path the operating system cannot represent (for example one containing a NUL character). Shows the usage line. |
|
||||||
| Folder not found | `<path>` does not exist or is not a folder. |
|
| Folder not found | `<path>` does not exist or is not a folder. |
|
||||||
| No workspace here | `<path>` exists but has no `.ykanban`. The **Initialize workspace** button creates one, with the columns To Do / In Progress / Done (named in the current interface language). |
|
| No workspace here | `<path>` exists but has no `.ykanban`. The **Initialize workspace** button creates one, with the columns To Do / In Progress / Done (named in the current interface language). |
|
||||||
| Workspace locked | Another YKanBan window already has this workspace open. Close that window first. |
|
| Workspace locked | Another YKanBan window already has this workspace open. Close that window first. Also shown when another window takes the lock while you initialize. |
|
||||||
| Cannot open workspace | The database was created by a newer YKanBan, is damaged or cannot be opened, or a file-system or permission error occurred (also when initializing fails). The English error details can be selected and copied. |
|
| Cannot open workspace | `.ykanban` exists but `ykanban.db` in it is missing (restore it from a backup, or delete `.ykanban` and initialize again; YKanBan never silently creates an empty board), the database was created by a newer YKanBan, is damaged or cannot be opened, or a file-system or permission error occurred (also when initializing fails for a reason other than the lock). The English error details can be selected and copied. |
|
||||||
|
|
||||||
The window title is `<workspace name> - YKanBan` while a workspace is open and
|
The window title is `<workspace name> - YKanBan` while a workspace is open and
|
||||||
just `YKanBan` on these pages.
|
just `YKanBan` on these pages.
|
||||||
@@ -80,11 +81,16 @@ Double-clicking `YKanBan.app` starts it without a path, so it only shows the
|
|||||||
Launch Services or by running the executable inside the bundle:
|
Launch Services or by running the executable inside the bundle:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
open -a YKanBan --args /path/to/project
|
open -n -a YKanBan --args /path/to/project
|
||||||
/Applications/YKanBan.app/Contents/MacOS/YKanBan /path/to/project
|
/Applications/YKanBan.app/Contents/MacOS/YKanBan /path/to/project
|
||||||
```
|
```
|
||||||
|
|
||||||
`open -a YKanBan` finds the app once it is in `/Applications` (or another
|
- Keep `-n`: without it, `open` only brings an already running YKanBan to
|
||||||
|
the front and drops the path, instead of starting another window.
|
||||||
|
- Give `open` an **absolute** path. An app started by `open` runs in `/`, so
|
||||||
|
`open -n -a YKanBan --args .` opens `/`, not the current folder. Running the
|
||||||
|
executable inside the bundle resolves relative paths normally.
|
||||||
|
- `open -a YKanBan` finds the app once it is in `/Applications` (or another
|
||||||
folder Launch Services knows about).
|
folder Launch Services knows about).
|
||||||
|
|
||||||
## Workspaces, Git and backups
|
## Workspaces, Git and backups
|
||||||
@@ -153,7 +159,7 @@ value := word | phrase -- tag / title / content / column
|
|||||||
| '#'? digit+ -- id: a positive decimal integer
|
| '#'? digit+ -- id: a positive decimal integer
|
||||||
word := one or more characters, except whitespace and ( ) " : \ ;
|
word := one or more characters, except whitespace and ( ) " : \ ;
|
||||||
not equal to AND or OR
|
not equal to AND or OR
|
||||||
phrase := '"' any text '"' -- escapes: \" and \\
|
phrase := '"' one or more characters '"' -- escapes: \" and \\
|
||||||
```
|
```
|
||||||
|
|
||||||
### Operators
|
### Operators
|
||||||
@@ -192,6 +198,10 @@ phrase := '"' any text '"' -- escapes: \" and \\
|
|||||||
`\\` for a backslash; any other backslash is an error.
|
`\\` for a backslash; any other backslash is an error.
|
||||||
- Outside quotes, `\` is not allowed at all, and `:` always starts a
|
- Outside quotes, `\` is not allowed at all, and `:` always starts a
|
||||||
qualifier. Quote any text containing them: `"C:\\temp"`, `"a:b"`.
|
qualifier. Quote any text containing them: `"C:\\temp"`, `"a:b"`.
|
||||||
|
- A phrase cannot be empty, and must be separated from neighbouring words
|
||||||
|
and phrases by a space or a parenthesis: write `a "b"`, not `a"b"`.
|
||||||
|
- A qualifier's phrase value follows the `:` directly: `tag:"needs review"`,
|
||||||
|
not `tag: "needs review"`.
|
||||||
|
|
||||||
### Case
|
### Case
|
||||||
|
|
||||||
@@ -215,11 +225,15 @@ These are invalid:
|
|||||||
| Problem | Example |
|
| Problem | Example |
|
||||||
|---|---|
|
|---|---|
|
||||||
| Unbalanced parentheses | `(tag:bug`, `tag:bug)` |
|
| Unbalanced parentheses | `(tag:bug`, `tag:bug)` |
|
||||||
|
| Parentheses nested more than 64 levels deep | `((((…a…))))` with 65 `(` |
|
||||||
| An operator with a missing side | `bug AND`, `OR bug` |
|
| An operator with a missing side | `bug AND`, `OR bug` |
|
||||||
| Consecutive operators | `a AND OR b` |
|
| Consecutive operators | `a AND OR b` |
|
||||||
| A qualifier without a value | `tag:` |
|
| A qualifier without a value | `tag:` |
|
||||||
| `AND` / `OR` as an unquoted qualifier value | `tag:AND` (write `tag:"AND"`) |
|
| `AND` / `OR` as an unquoted qualifier value | `tag:AND` (write `tag:"AND"`) |
|
||||||
| An unterminated phrase | `"dark mode` |
|
| An unterminated phrase | `"dark mode` |
|
||||||
|
| An empty phrase | `""`, `tag:""` |
|
||||||
|
| A phrase touching other text | `a"b"`, `"a"b`, `"a""b"` |
|
||||||
|
| A space between a qualifier and its phrase value | `tag: "needs review"` |
|
||||||
| An invalid escape in a phrase | `tag:"a\x"` |
|
| An invalid escape in a phrase | `tag:"a\x"` |
|
||||||
| A backslash outside a phrase | `C:\temp` |
|
| A backslash outside a phrase | `C:\temp` |
|
||||||
| An unknown qualifier key | `label:bug`, `Tag:bug`, `http://x` |
|
| An unknown qualifier key | `label:bug`, `Tag:bug`, `http://x` |
|
||||||
|
|||||||
@@ -123,7 +123,7 @@ public class MarkdownExporterTests
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Normalizes CRLF line endings so expected and actual compare consistently.
|
/// Normalizes the expected document, built with the platform newline, to the exporter's LF.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="text">The text to normalize.</param>
|
/// <param name="text">The text to normalize.</param>
|
||||||
/// <returns>The text with normalized line endings.</returns>
|
/// <returns>The text with normalized line endings.</returns>
|
||||||
@@ -139,7 +139,7 @@ public class MarkdownExporterTests
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
Resources.Culture = culture;
|
Resources.Culture = culture;
|
||||||
Assert.AreEqual(Normalize(BuildExpected(culture)), Normalize(ExportBoard()));
|
Assert.AreEqual(Normalize(BuildExpected(culture)), ExportBoard());
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
@@ -204,6 +204,29 @@ public class MarkdownExporterTests
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void TagTableCellsEscapeBackslashesSoAPipeAfterOneStaysEscaped()
|
||||||
|
{
|
||||||
|
CultureInfo? original = Resources.Culture;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Resources.Culture = new CultureInfo("en");
|
||||||
|
var tag = new TagModel(1, @"a\|b", RgbColor.Parse("#112233"), @"C:\temp\");
|
||||||
|
string markdown = MarkdownExporter.Export(
|
||||||
|
"W",
|
||||||
|
[new ColumnModel(1, "C", string.Empty, 1, 1)],
|
||||||
|
[],
|
||||||
|
[(tag, 0L)],
|
||||||
|
ExportedAt);
|
||||||
|
|
||||||
|
StringAssert.Contains(markdown, @"| a\\\|b | #112233 | C:\\temp\\ | 0 |");
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
Resources.Culture = original;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
[DataRow("plain", "`plain`")]
|
[DataRow("plain", "`plain`")]
|
||||||
[DataRow("a`b", "``a`b``")]
|
[DataRow("a`b", "``a`b``")]
|
||||||
@@ -225,7 +248,7 @@ public class MarkdownExporterTests
|
|||||||
[(tag, 1L)],
|
[(tag, 1L)],
|
||||||
ExportedAt);
|
ExportedAt);
|
||||||
|
|
||||||
StringAssert.Contains(markdown, string.Format(Resources.Culture, Resources.Export_TagsLine, expected) + Environment.NewLine);
|
StringAssert.Contains(markdown, string.Format(Resources.Culture, Resources.Export_TagsLine, expected) + "\n");
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
@@ -240,12 +263,12 @@ public class MarkdownExporterTests
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
Resources.Culture = new CultureInfo("en");
|
Resources.Culture = new CultureInfo("en");
|
||||||
string markdown = Normalize(MarkdownExporter.Export(
|
string markdown = MarkdownExporter.Export(
|
||||||
"W",
|
"W",
|
||||||
[new ColumnModel(1, "C", "line one\n# not a heading | pipe", 1, 1)],
|
[new ColumnModel(1, "C", "line one\n# not a heading | pipe", 1, 1)],
|
||||||
[new CardModel(1, 1, "T", "body\n\n## raw | `md`", 1, 1, [])],
|
[new CardModel(1, 1, "T", "body\n\n## raw | `md`", 1, 1, [])],
|
||||||
[],
|
[],
|
||||||
ExportedAt));
|
ExportedAt);
|
||||||
|
|
||||||
StringAssert.Contains(markdown, "\nline one\n# not a heading | pipe\n");
|
StringAssert.Contains(markdown, "\nline one\n# not a heading | pipe\n");
|
||||||
StringAssert.Contains(markdown, "\nbody\n\n## raw | `md`\n");
|
StringAssert.Contains(markdown, "\nbody\n\n## raw | `md`\n");
|
||||||
@@ -256,6 +279,53 @@ public class MarkdownExporterTests
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void LineEndingsAreLfOnEveryPlatform()
|
||||||
|
{
|
||||||
|
CultureInfo? original = Resources.Culture;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Resources.Culture = new CultureInfo("en");
|
||||||
|
string markdown = MarkdownExporter.Export(
|
||||||
|
"W",
|
||||||
|
[new ColumnModel(1, "C", "one\r\ntwo\rthree", 1, 1)],
|
||||||
|
[new CardModel(1, 1, "T", "a\r\nb", 1, 1, [])],
|
||||||
|
[],
|
||||||
|
ExportedAt);
|
||||||
|
|
||||||
|
Assert.IsFalse(markdown.Contains('\r'));
|
||||||
|
StringAssert.Contains(markdown, "\none\ntwo\nthree\n");
|
||||||
|
StringAssert.Contains(markdown, "\na\nb\n");
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
Resources.Culture = original;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void ColumnTitleIsCollapsedToOneLine()
|
||||||
|
{
|
||||||
|
CultureInfo? original = Resources.Culture;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Resources.Culture = new CultureInfo("en");
|
||||||
|
string markdown = MarkdownExporter.Export(
|
||||||
|
"W",
|
||||||
|
[new ColumnModel(1, "To\r\nDo\nNow", string.Empty, 1, 1)],
|
||||||
|
[],
|
||||||
|
[],
|
||||||
|
ExportedAt);
|
||||||
|
|
||||||
|
string heading = string.Format(Resources.Culture, Resources.Export_ColumnHeading, "To Do Now", 0);
|
||||||
|
StringAssert.Contains(markdown, "\n" + heading + "\n");
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
Resources.Culture = original;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void ColumnsAndCardsAreExportedInIdOrder()
|
public void ColumnsAndCardsAreExportedInIdOrder()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ public class CardOrderingTests
|
|||||||
public void TitleSortsSupplementaryCharactersAfterBmpPrivateUse()
|
public void TitleSortsSupplementaryCharactersAfterBmpPrivateUse()
|
||||||
{
|
{
|
||||||
// U+1F600 is a surrogate pair in UTF-16, so ordinal comparison would put it before U+E000.
|
// U+1F600 is a surrogate pair in UTF-16, so ordinal comparison would put it before U+E000.
|
||||||
CardModel[] cards = [Card(1, "\U0001F600"), Card(2, "")];
|
CardModel[] cards = [Card(1, "\U0001F600"), Card(2, "\uE000")];
|
||||||
CollectionAssert.AreEqual(new[] { 2L, 1L }, Ids(cards, CardSortOption.Title));
|
CollectionAssert.AreEqual(new[] { 2L, 1L }, Ids(cards, CardSortOption.Title));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -227,6 +227,33 @@ public class SearchQueryParserTests
|
|||||||
AssertSyntaxError("a)");
|
AssertSyntaxError("a)");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void NestingAtTheDepthLimitParses()
|
||||||
|
{
|
||||||
|
int depth = SearchQueryParser.MaxNestingDepth;
|
||||||
|
AssertParsesTo(new SearchNode.FreeText("a"), new string('(', depth) + "a" + new string(')', depth));
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void NestingBeyondTheDepthLimitIsAnError()
|
||||||
|
{
|
||||||
|
int depth = SearchQueryParser.MaxNestingDepth + 1;
|
||||||
|
AssertSyntaxError(new string('(', depth) + "a" + new string(')', depth));
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void SequentialGroupsDoNotCountTowardsTheDepthLimit()
|
||||||
|
{
|
||||||
|
string groups = string.Join(" ", Enumerable.Repeat("(a)", SearchQueryParser.MaxNestingDepth + 1));
|
||||||
|
Assert.IsNotNull(SearchQueryParser.Parse(groups));
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void VeryDeepNestingIsAnErrorRatherThanACrash()
|
||||||
|
{
|
||||||
|
AssertSyntaxError(new string('(', 100_000) + "a" + new string(')', 100_000));
|
||||||
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void EmptyParensAreAnError()
|
public void EmptyParensAreAnError()
|
||||||
{
|
{
|
||||||
@@ -269,6 +296,42 @@ public class SearchQueryParserTests
|
|||||||
AssertSyntaxError("tag: bug");
|
AssertSyntaxError("tag: bug");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
[DataRow("tag: \"x\"")]
|
||||||
|
[DataRow("title: \"a b\"")]
|
||||||
|
public void SpacedQualifierPhraseValueIsAnError(string text)
|
||||||
|
{
|
||||||
|
AssertSyntaxError(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
[DataRow("a\"b\"")]
|
||||||
|
[DataRow("\"a\"b")]
|
||||||
|
[DataRow("\"a\"\"b\"")]
|
||||||
|
[DataRow("tag:\"x\"y")]
|
||||||
|
[DataRow("tag:\"x\"\"y\"")]
|
||||||
|
public void PhraseGluedToOtherTextIsAnError(string text)
|
||||||
|
{
|
||||||
|
AssertSyntaxError(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
[DataRow("\"\"")]
|
||||||
|
[DataRow("a \"\"")]
|
||||||
|
[DataRow("tag:\"\"")]
|
||||||
|
public void EmptyPhraseIsAnError(string text)
|
||||||
|
{
|
||||||
|
AssertSyntaxError(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void PhraseMayTouchParentheses()
|
||||||
|
{
|
||||||
|
AssertParsesTo(
|
||||||
|
new SearchNode.And([new SearchNode.FreeText("a b"), new SearchNode.FreeText("c")]),
|
||||||
|
"(\"a b\")(c)");
|
||||||
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
[DataRow("id:12x")]
|
[DataRow("id:12x")]
|
||||||
[DataRow("id:abc")]
|
[DataRow("id:abc")]
|
||||||
|
|||||||
@@ -80,4 +80,48 @@ public class SqliteDatabaseTests
|
|||||||
|
|
||||||
Assert.ThrowsExactly<ArgumentException>(() => SqliteDatabase.Open(databasePath, broken));
|
Assert.ThrowsExactly<ArgumentException>(() => SqliteDatabase.Open(databasePath, broken));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void CreateBuildsSchemaAndSeedTogether()
|
||||||
|
{
|
||||||
|
using var directory = new TempDirectory();
|
||||||
|
string databasePath = Path.Combine(directory.FullPath, "create.db");
|
||||||
|
|
||||||
|
using SqliteConnection connection = SqliteDatabase.Create(databasePath, WorkspaceSchema.Migrations,
|
||||||
|
(seedConnection, transaction) =>
|
||||||
|
{
|
||||||
|
using SqliteCommand command = seedConnection.CreateCommand();
|
||||||
|
command.Transaction = transaction;
|
||||||
|
command.CommandText = "INSERT INTO tags (name, color) VALUES ('seed', '#000000');";
|
||||||
|
command.ExecuteNonQuery();
|
||||||
|
});
|
||||||
|
Assert.AreEqual(WorkspaceSchema.CurrentVersion, SqliteDatabase.ReadUserVersion(connection));
|
||||||
|
Assert.AreEqual(1L, SqliteTestHelper.ScalarLong(connection, "SELECT COUNT(*) FROM tags;"));
|
||||||
|
Assert.AreEqual("wal", SqliteTestHelper.ScalarString(connection, "PRAGMA journal_mode;"));
|
||||||
|
Assert.AreEqual(1L, SqliteTestHelper.ScalarLong(connection, "PRAGMA foreign_keys;"));
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void CreateWithFailingSeedLeavesNoDatabaseBehind()
|
||||||
|
{
|
||||||
|
using var directory = new TempDirectory();
|
||||||
|
string databasePath = Path.Combine(directory.FullPath, "failed.db");
|
||||||
|
|
||||||
|
Assert.ThrowsExactly<InvalidOperationException>(() => SqliteDatabase.Create(
|
||||||
|
databasePath, WorkspaceSchema.Migrations, (_, _) => throw new InvalidOperationException("seed failed")));
|
||||||
|
Assert.IsFalse(File.Exists(databasePath));
|
||||||
|
Assert.IsFalse(File.Exists(databasePath + "-wal"));
|
||||||
|
Assert.IsFalse(File.Exists(databasePath + "-shm"));
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void CreateRefusesAnExistingDatabaseAndKeepsIt()
|
||||||
|
{
|
||||||
|
using var directory = new TempDirectory();
|
||||||
|
string databasePath = Path.Combine(directory.FullPath, "existing.db");
|
||||||
|
SqliteDatabase.Create(databasePath, WorkspaceSchema.Migrations).Dispose();
|
||||||
|
|
||||||
|
Assert.ThrowsExactly<InvalidOperationException>(() => SqliteDatabase.Create(databasePath, WorkspaceSchema.Migrations));
|
||||||
|
Assert.IsTrue(File.Exists(databasePath));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -29,8 +29,7 @@ public class WorkspacePresetTests
|
|||||||
];
|
];
|
||||||
|
|
||||||
using var directory = new TempDirectory();
|
using var directory = new TempDirectory();
|
||||||
WorkspaceInitializer.Initialize(directory.FullPath);
|
WorkspaceSession.Initialize(directory.FullPath).Dispose();
|
||||||
WorkspacePreset.AddPresetColumns(directory.FullPath);
|
|
||||||
|
|
||||||
using SqliteConnection connection = SqliteTestHelper.OpenWorkspace(directory.FullPath);
|
using SqliteConnection connection = SqliteTestHelper.OpenWorkspace(directory.FullPath);
|
||||||
CollectionAssert.AreEqual(expected, SqliteTestHelper.GetColumnTitles(connection));
|
CollectionAssert.AreEqual(expected, SqliteTestHelper.GetColumnTitles(connection));
|
||||||
@@ -56,8 +55,7 @@ public class WorkspacePresetTests
|
|||||||
];
|
];
|
||||||
|
|
||||||
using var directory = new TempDirectory();
|
using var directory = new TempDirectory();
|
||||||
WorkspaceInitializer.Initialize(directory.FullPath);
|
WorkspaceSession.Initialize(directory.FullPath).Dispose();
|
||||||
WorkspacePreset.AddPresetColumns(directory.FullPath);
|
|
||||||
|
|
||||||
using SqliteConnection connection = SqliteTestHelper.OpenWorkspace(directory.FullPath);
|
using SqliteConnection connection = SqliteTestHelper.OpenWorkspace(directory.FullPath);
|
||||||
CollectionAssert.AreEqual(expected, SqliteTestHelper.GetColumnTitles(connection));
|
CollectionAssert.AreEqual(expected, SqliteTestHelper.GetColumnTitles(connection));
|
||||||
@@ -83,8 +81,7 @@ public class WorkspacePresetTests
|
|||||||
];
|
];
|
||||||
|
|
||||||
using var directory = new TempDirectory();
|
using var directory = new TempDirectory();
|
||||||
WorkspaceInitializer.Initialize(directory.FullPath);
|
WorkspaceSession.Initialize(directory.FullPath).Dispose();
|
||||||
WorkspacePreset.AddPresetColumns(directory.FullPath);
|
|
||||||
|
|
||||||
// Switching the language after adding the presets must not rewrite stored data.
|
// Switching the language after adding the presets must not rewrite stored data.
|
||||||
Resources.Culture = new CultureInfo("zh-Hans");
|
Resources.Culture = new CultureInfo("zh-Hans");
|
||||||
|
|||||||
@@ -57,4 +57,51 @@ public class WorkspaceSessionTests
|
|||||||
Assert.AreEqual("bug", session.Repository.GetTags().Single().Name);
|
Assert.AreEqual("bug", session.Repository.GetTags().Single().Name);
|
||||||
Assert.AreEqual(tag.Id, session.Repository.GetTags().Single().Id);
|
Assert.AreEqual(tag.Id, session.Repository.GetTags().Single().Id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void InitializeAddsPresetColumnsAndHoldsTheLock()
|
||||||
|
{
|
||||||
|
using var directory = new TempDirectory();
|
||||||
|
|
||||||
|
using WorkspaceSession session = WorkspaceSession.Initialize(directory.FullPath);
|
||||||
|
Assert.AreEqual(3, session.Repository.GetColumns().Count);
|
||||||
|
Assert.ThrowsExactly<WorkspaceLockException>(() => WorkspaceSession.Open(directory.FullPath));
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void InitializeWhileAnotherInstanceHoldsTheLockThrowsLockConflict()
|
||||||
|
{
|
||||||
|
using var directory = new TempDirectory();
|
||||||
|
Directory.CreateDirectory(WorkspacePaths.Root(directory.FullPath));
|
||||||
|
using WorkspaceLock held = WorkspaceLock.Acquire(directory.FullPath);
|
||||||
|
|
||||||
|
Assert.ThrowsExactly<WorkspaceLockException>(() => WorkspaceSession.Initialize(directory.FullPath));
|
||||||
|
Assert.IsFalse(File.Exists(WorkspacePaths.Database(directory.FullPath)));
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void FailedInitializeReleasesTheLock()
|
||||||
|
{
|
||||||
|
using var directory = new TempDirectory();
|
||||||
|
WorkspaceInitializer.Initialize(directory.FullPath);
|
||||||
|
|
||||||
|
// The database already exists, so initialization fails after taking the lock.
|
||||||
|
Assert.ThrowsExactly<InvalidOperationException>(() => WorkspaceSession.Initialize(directory.FullPath));
|
||||||
|
using WorkspaceSession reopened = WorkspaceSession.Open(directory.FullPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void OpenWithMissingDatabaseThrowsAndCreatesNothing()
|
||||||
|
{
|
||||||
|
using var directory = new TempDirectory();
|
||||||
|
WorkspaceInitializer.Initialize(directory.FullPath);
|
||||||
|
string databasePath = WorkspacePaths.Database(directory.FullPath);
|
||||||
|
File.Delete(databasePath);
|
||||||
|
|
||||||
|
Assert.ThrowsExactly<WorkspaceDatabaseMissingException>(() => WorkspaceSession.Open(directory.FullPath));
|
||||||
|
Assert.IsFalse(File.Exists(databasePath));
|
||||||
|
|
||||||
|
// The lock was released again: the next attempt fails the same way, not with a lock conflict.
|
||||||
|
Assert.ThrowsExactly<WorkspaceDatabaseMissingException>(() => WorkspaceSession.Open(directory.FullPath));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -43,6 +43,9 @@ public class OpenFailedPageViewModelTests
|
|||||||
Assert.AreEqual(
|
Assert.AreEqual(
|
||||||
Expected(Resources.Error_OpenFailed_SchemaTooNew, 3L, 1),
|
Expected(Resources.Error_OpenFailed_SchemaTooNew, 3L, 1),
|
||||||
OpenFailedPageViewModel.BuildMessage(Folder, new SchemaVersionException(3, 1)));
|
OpenFailedPageViewModel.BuildMessage(Folder, new SchemaVersionException(3, 1)));
|
||||||
|
Assert.AreEqual(
|
||||||
|
Expected(Resources.Error_OpenFailed_DatabaseMissing),
|
||||||
|
OpenFailedPageViewModel.BuildMessage(Folder, new WorkspaceDatabaseMissingException("/work/repo/.ykanban/ykanban.db")));
|
||||||
Assert.AreEqual(
|
Assert.AreEqual(
|
||||||
Expected(Resources.Error_OpenFailed_Database),
|
Expected(Resources.Error_OpenFailed_Database),
|
||||||
OpenFailedPageViewModel.BuildMessage(Folder, new SqliteException("file is not a database", 26)));
|
OpenFailedPageViewModel.BuildMessage(Folder, new SqliteException("file is not a database", 26)));
|
||||||
|
|||||||
@@ -79,6 +79,9 @@
|
|||||||
<data name="Error_OpenFailed_Database" xml:space="preserve">
|
<data name="Error_OpenFailed_Database" xml:space="preserve">
|
||||||
<value>The workspace database cannot be opened or is damaged: {0}</value>
|
<value>The workspace database cannot be opened or is damaged: {0}</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="Error_OpenFailed_DatabaseMissing" xml:space="preserve">
|
||||||
|
<value>The workspace database (.ykanban/ykanban.db) is missing. Restore it from a backup together with its -wal and -shm files, or delete the .ykanban folder to initialize the workspace again: {0}</value>
|
||||||
|
</data>
|
||||||
<data name="Error_OpenFailed_AccessDenied" xml:space="preserve">
|
<data name="Error_OpenFailed_AccessDenied" xml:space="preserve">
|
||||||
<value>Access to the workspace was denied: {0}</value>
|
<value>Access to the workspace was denied: {0}</value>
|
||||||
</data>
|
</data>
|
||||||
|
|||||||
@@ -79,6 +79,9 @@
|
|||||||
<data name="Error_OpenFailed_Database" xml:space="preserve">
|
<data name="Error_OpenFailed_Database" xml:space="preserve">
|
||||||
<value>工作区数据库无法打开或已损坏:{0}</value>
|
<value>工作区数据库无法打开或已损坏:{0}</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="Error_OpenFailed_DatabaseMissing" xml:space="preserve">
|
||||||
|
<value>工作区数据库(.ykanban/ykanban.db)不存在。请从备份恢复(连同 -wal、-shm 文件),或删除 .ykanban 文件夹后重新初始化:{0}</value>
|
||||||
|
</data>
|
||||||
<data name="Error_OpenFailed_AccessDenied" xml:space="preserve">
|
<data name="Error_OpenFailed_AccessDenied" xml:space="preserve">
|
||||||
<value>没有访问该工作区的权限:{0}</value>
|
<value>没有访问该工作区的权限:{0}</value>
|
||||||
</data>
|
</data>
|
||||||
|
|||||||
@@ -8,9 +8,10 @@ namespace YKanBan.Export;
|
|||||||
/// Generates the human-readable Markdown snapshot of a whole board. All
|
/// Generates the human-readable Markdown snapshot of a whole board. All
|
||||||
/// template text and the time format come from the ResX resources in the current
|
/// template text and the time format come from the ResX resources in the current
|
||||||
/// UI language; every timestamp (export time and card created/modified times)
|
/// UI language; every timestamp (export time and card created/modified times)
|
||||||
/// uses that one per-language pattern. Card bodies and column descriptions are
|
/// uses that one per-language pattern. The whole document uses LF line endings
|
||||||
/// emitted verbatim; tag names become inline code with a long enough backtick
|
/// on every platform. Card bodies and column descriptions are emitted verbatim
|
||||||
/// fence; tag table cells escape '|' and turn line breaks into <br>. The
|
/// apart from line endings; column and card titles are collapsed to one line;
|
||||||
|
/// tag names become inline code with a long enough backtick fence; tag table cells escape '\' and '|' and turn line breaks into <br>. The
|
||||||
/// output is meant for reading only — there is no re-import.
|
/// output is meant for reading only — there is no re-import.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static class MarkdownExporter
|
public static class MarkdownExporter
|
||||||
@@ -36,10 +37,10 @@ public static class MarkdownExporter
|
|||||||
var builder = new StringBuilder();
|
var builder = new StringBuilder();
|
||||||
|
|
||||||
// Header: workspace name and the export timestamp in the UI language's format.
|
// Header: workspace name and the export timestamp in the UI language's format.
|
||||||
builder.AppendLine(string.Format(culture, Resources.Export_WorkspaceHeading, workspaceName));
|
AppendLine(builder, string.Format(culture, Resources.Export_WorkspaceHeading, SingleLine(workspaceName)));
|
||||||
builder.AppendLine(string.Format(
|
AppendLine(builder, string.Format(
|
||||||
culture, Resources.Export_ExportedAtLine, exportedAt.ToString(Resources.Export_TimePattern, culture)));
|
culture, Resources.Export_ExportedAtLine, exportedAt.ToString(Resources.Export_TimePattern, culture)));
|
||||||
builder.AppendLine();
|
AppendLine(builder);
|
||||||
|
|
||||||
// Board body: every column in id order, empty ones included; independent of
|
// Board body: every column in id order, empty ones included; independent of
|
||||||
// the board's search filter and card sort option.
|
// the board's search filter and card sort option.
|
||||||
@@ -47,12 +48,12 @@ public static class MarkdownExporter
|
|||||||
{
|
{
|
||||||
IReadOnlyList<CardModel> cardsInColumn =
|
IReadOnlyList<CardModel> cardsInColumn =
|
||||||
cards.Where(card => card.ColumnId == column.Id).OrderBy(card => card.Id).ToArray();
|
cards.Where(card => card.ColumnId == column.Id).OrderBy(card => card.Id).ToArray();
|
||||||
builder.AppendLine(string.Format(culture, Resources.Export_ColumnHeading, column.Title, cardsInColumn.Count));
|
AppendLine(builder, string.Format(culture, Resources.Export_ColumnHeading, SingleLine(column.Title), cardsInColumn.Count));
|
||||||
if (column.Description.Length > 0)
|
if (column.Description.Length > 0)
|
||||||
{
|
{
|
||||||
builder.AppendLine(column.Description);
|
AppendLine(builder, ToLf(column.Description));
|
||||||
}
|
}
|
||||||
builder.AppendLine();
|
AppendLine(builder);
|
||||||
|
|
||||||
foreach (CardModel card in cardsInColumn)
|
foreach (CardModel card in cardsInColumn)
|
||||||
{
|
{
|
||||||
@@ -86,25 +87,25 @@ public static class MarkdownExporter
|
|||||||
private static void AppendCard(StringBuilder builder, CardModel card, CultureInfo culture)
|
private static void AppendCard(StringBuilder builder, CardModel card, CultureInfo culture)
|
||||||
{
|
{
|
||||||
// Heading: "#id title"; an untitled card shows only the id.
|
// Heading: "#id title"; an untitled card shows only the id.
|
||||||
builder.AppendLine(card.Title.Length == 0
|
AppendLine(builder, card.Title.Length == 0
|
||||||
? $"### #{card.Id}"
|
? $"### #{card.Id}"
|
||||||
: $"### #{card.Id} {SingleLine(card.Title)}");
|
: $"### #{card.Id} {SingleLine(card.Title)}");
|
||||||
|
|
||||||
if (card.Content.Length > 0)
|
if (card.Content.Length > 0)
|
||||||
{
|
{
|
||||||
builder.AppendLine(card.Content);
|
AppendLine(builder, ToLf(card.Content));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (card.Tags.Count > 0)
|
if (card.Tags.Count > 0)
|
||||||
{
|
{
|
||||||
string names = string.Join(" ", card.Tags.Select(tag => InlineCode(tag.Name)));
|
string names = string.Join(" ", card.Tags.Select(tag => InlineCode(tag.Name)));
|
||||||
builder.AppendLine(string.Format(culture, Resources.Export_TagsLine, names));
|
AppendLine(builder, string.Format(culture, Resources.Export_TagsLine, names));
|
||||||
}
|
}
|
||||||
|
|
||||||
string created = ToLocalTime(card.CreatedAt).ToString(Resources.Export_TimePattern, culture);
|
string created = ToLocalTime(card.CreatedAt).ToString(Resources.Export_TimePattern, culture);
|
||||||
string updated = ToLocalTime(card.UpdatedAt).ToString(Resources.Export_TimePattern, culture);
|
string updated = ToLocalTime(card.UpdatedAt).ToString(Resources.Export_TimePattern, culture);
|
||||||
builder.AppendLine(string.Format(culture, Resources.Export_CreatedModifiedLine, created, updated));
|
AppendLine(builder, string.Format(culture, Resources.Export_CreatedModifiedLine, created, updated));
|
||||||
builder.AppendLine();
|
AppendLine(builder);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -118,23 +119,25 @@ public static class MarkdownExporter
|
|||||||
IReadOnlyList<(TagModel Tag, long UsageCount)> tags,
|
IReadOnlyList<(TagModel Tag, long UsageCount)> tags,
|
||||||
CultureInfo culture)
|
CultureInfo culture)
|
||||||
{
|
{
|
||||||
builder.AppendLine(Resources.Export_TagsSummaryHeading);
|
AppendLine(builder, Resources.Export_TagsSummaryHeading);
|
||||||
builder.AppendLine(Resources.Export_TagsTableHeader);
|
AppendLine(builder, Resources.Export_TagsTableHeader);
|
||||||
builder.AppendLine("|---|---|---|---|");
|
AppendLine(builder, "|---|---|---|---|");
|
||||||
foreach ((TagModel tag, long usage) in tags)
|
foreach ((TagModel tag, long usage) in tags)
|
||||||
{
|
{
|
||||||
// '|' and line breaks would break the table row; neutralize them.
|
// '|' and line breaks would break the table row; neutralize them.
|
||||||
builder.AppendLine($"| {Cell(tag.Name)} | {tag.Color} | {Cell(tag.Description)} | {usage} |");
|
AppendLine(builder, $"| {Cell(tag.Name)} | {tag.Color} | {Cell(tag.Description)} | {usage} |");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Formats a table cell: escaped pipe characters, line breaks as <br>.
|
/// Formats a table cell: escaped backslashes and pipe characters, line breaks as <br>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="text">The raw cell text.</param>
|
/// <param name="text">The raw cell text.</param>
|
||||||
/// <returns>The escaped single-line text.</returns>
|
/// <returns>The escaped single-line text.</returns>
|
||||||
private static string Cell(string text) =>
|
private static string Cell(string text) =>
|
||||||
text.Replace("|", "\\|").Replace("\r\n", "<br>").Replace("\r", "<br>").Replace("\n", "<br>");
|
// Backslashes first: the table splitter reads "\\" as an escaped backslash, so the
|
||||||
|
// '|' after a literal backslash would otherwise end the cell.
|
||||||
|
text.Replace("\\", "\\\\").Replace("|", "\\|").Replace("\r\n", "<br>").Replace("\r", "<br>").Replace("\n", "<br>");
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Renders text as an inline code span whose backtick fence is one longer than
|
/// Renders text as an inline code span whose backtick fence is one longer than
|
||||||
@@ -158,6 +161,20 @@ public static class MarkdownExporter
|
|||||||
return fence + padding + text + padding + fence;
|
return fence + padding + text + padding + fence;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Appends a line terminated by LF, whatever the platform's newline.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="builder">The output builder.</param>
|
||||||
|
/// <param name="text">The line text; empty for a blank line.</param>
|
||||||
|
private static void AppendLine(StringBuilder builder, string text = "") => builder.Append(text).Append('\n');
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Converts CRLF and lone CR line breaks to LF.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="text">The raw text.</param>
|
||||||
|
/// <returns>The text with LF line breaks only.</returns>
|
||||||
|
private static string ToLf(string text) => text.Replace("\r\n", "\n").Replace('\r', '\n');
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Collapses line breaks so the text stays on one Markdown line.
|
/// Collapses line breaks so the text stays on one Markdown line.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -36,8 +36,11 @@ public abstract record SearchToken
|
|||||||
///
|
///
|
||||||
/// The lexer is strict: inside a phrase only <c>\"</c> and <c>\\</c> are valid
|
/// The lexer is strict: inside a phrase only <c>\"</c> and <c>\\</c> are valid
|
||||||
/// escapes, a bare backslash or an unknown escape is rejected, a backslash in a
|
/// escapes, a bare backslash or an unknown escape is rejected, a backslash in a
|
||||||
/// bare word is rejected, and an unterminated phrase is rejected. Any input not covered by the token rules
|
/// bare word is rejected, and an unterminated phrase is rejected. A phrase
|
||||||
/// is rejected rather than silently ignored.
|
/// must not be empty and must be separated from neighbouring words and
|
||||||
|
/// phrases by whitespace or a parenthesis, except as a qualifier value glued to
|
||||||
|
/// its key (<c>tag:"a b"</c>). Any input not covered by the token rules is
|
||||||
|
/// rejected rather than silently ignored.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static class SearchLexer
|
public static class SearchLexer
|
||||||
{
|
{
|
||||||
@@ -70,37 +73,101 @@ public static class SearchLexer
|
|||||||
.AtLeastOnce()
|
.AtLeastOnce()
|
||||||
.Select(chars => (SearchToken)new SearchToken.Word(new string(chars.ToArray())));
|
.Select(chars => (SearchToken)new SearchToken.Word(new string(chars.ToArray())));
|
||||||
|
|
||||||
private static readonly Parser<char, SearchToken> TokenParser =
|
// Each token with its source span, so adjacency can be checked afterwards.
|
||||||
|
private static readonly Parser<char, PositionedToken> TokenParser =
|
||||||
Parser.SkipWhitespaces.Then(
|
Parser.SkipWhitespaces.Then(
|
||||||
PhraseParser
|
from start in Parser<char>.CurrentOffset
|
||||||
|
from token in PhraseParser
|
||||||
.Or(OpenParenParser)
|
.Or(OpenParenParser)
|
||||||
.Or(CloseParenParser)
|
.Or(CloseParenParser)
|
||||||
.Or(WordParser));
|
.Or(WordParser)
|
||||||
|
from end in Parser<char>.CurrentOffset
|
||||||
|
select new PositionedToken(token, start, end));
|
||||||
|
|
||||||
// Try(...) keeps a failed token non-consuming so Many stops gracefully; End
|
// Try(...) keeps a failed token non-consuming so Many stops gracefully; End
|
||||||
// then rejects any leftover input, which turns dangling quotes or invalid
|
// then rejects any leftover input, which turns dangling quotes or invalid
|
||||||
// escapes into hard failures instead of silently dropped text.
|
// escapes into hard failures instead of silently dropped text.
|
||||||
private static readonly Parser<char, IReadOnlyList<SearchToken>> Lexer =
|
private static readonly Parser<char, IReadOnlyList<PositionedToken>> Lexer =
|
||||||
Parser.Try(TokenParser).Many()
|
Parser.Try(TokenParser).Many()
|
||||||
.Before(Parser.SkipWhitespaces)
|
.Before(Parser.SkipWhitespaces)
|
||||||
.Before(Parser<char>.End)
|
.Before(Parser<char>.End)
|
||||||
.Select(tokens => (IReadOnlyList<SearchToken>)tokens.ToList());
|
.Select(tokens => (IReadOnlyList<PositionedToken>)tokens.ToList());
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Tokenizes the search text.
|
/// Tokenizes the search text.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="input">The raw search text.</param>
|
/// <param name="input">The raw search text.</param>
|
||||||
/// <returns>The token stream.</returns>
|
/// <returns>The token stream.</returns>
|
||||||
/// <exception cref="SearchSyntaxException">The text contains an invalid escape or an unterminated phrase.</exception>
|
/// <exception cref="SearchSyntaxException">
|
||||||
|
/// The text contains an invalid escape, an unterminated or empty phrase, a
|
||||||
|
/// phrase glued to other text, or whitespace between a qualifier and its phrase value.
|
||||||
|
/// </exception>
|
||||||
public static IReadOnlyList<SearchToken> Tokenize(string input)
|
public static IReadOnlyList<SearchToken> Tokenize(string input)
|
||||||
{
|
{
|
||||||
|
IReadOnlyList<PositionedToken> tokens;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return Lexer.ParseOrThrow(input);
|
tokens = Lexer.ParseOrThrow(input);
|
||||||
}
|
}
|
||||||
catch (ParseException exception)
|
catch (ParseException exception)
|
||||||
{
|
{
|
||||||
throw new SearchSyntaxException(exception.Message, exception);
|
throw new SearchSyntaxException(exception.Message, exception);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
EnsurePhrasesAreDelimited(tokens);
|
||||||
|
return tokens.Select(positioned => positioned.Token).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Rejects the phrase placements the grammar does not allow but the token
|
||||||
|
/// rules alone would accept: an empty phrase, a phrase touching a word or
|
||||||
|
/// another phrase (<c>a"b"</c>, <c>"a"b</c>, <c>"a""b"</c>), and whitespace
|
||||||
|
/// between <c>key:</c> and its phrase value (<c>tag: "x"</c>). The only
|
||||||
|
/// legal contact is <c>key:"value"</c>.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="tokens">The positioned token stream.</param>
|
||||||
|
/// <exception cref="SearchSyntaxException">A phrase is misplaced.</exception>
|
||||||
|
private static void EnsurePhrasesAreDelimited(IReadOnlyList<PositionedToken> tokens)
|
||||||
|
{
|
||||||
|
for (int index = 0; index < tokens.Count; index++)
|
||||||
|
{
|
||||||
|
if (tokens[index].Token is SearchToken.Phrase { Text.Length: 0 })
|
||||||
|
{
|
||||||
|
throw new SearchSyntaxException("Empty phrase \"\" is not allowed.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (index == 0)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
PositionedToken previous = tokens[index - 1];
|
||||||
|
PositionedToken current = tokens[index];
|
||||||
|
bool qualifierValue = previous.Token is SearchToken.Word word && word.Text.EndsWith(':')
|
||||||
|
&& current.Token is SearchToken.Phrase;
|
||||||
|
bool touching = previous.End == current.Start;
|
||||||
|
|
||||||
|
if (qualifierValue && !touching)
|
||||||
|
{
|
||||||
|
throw new SearchSyntaxException(
|
||||||
|
$"Qualifier '{((SearchToken.Word)previous.Token).Text}' must be followed directly by its value, without whitespace.");
|
||||||
|
}
|
||||||
|
|
||||||
|
bool phraseInvolved = previous.Token is SearchToken.Phrase || current.Token is SearchToken.Phrase;
|
||||||
|
bool parenInvolved = previous.Token is SearchToken.OpenParen or SearchToken.CloseParen
|
||||||
|
|| current.Token is SearchToken.OpenParen or SearchToken.CloseParen;
|
||||||
|
if (touching && phraseInvolved && !parenInvolved && !qualifierValue)
|
||||||
|
{
|
||||||
|
throw new SearchSyntaxException("A phrase must be separated from adjacent text by whitespace.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A token with its source span.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="Token">The token.</param>
|
||||||
|
/// <param name="Start">Offset of the first character.</param>
|
||||||
|
/// <param name="End">Offset just past the last character.</param>
|
||||||
|
private sealed record PositionedToken(SearchToken Token, int Start, int End);
|
||||||
|
}
|
||||||
@@ -8,8 +8,9 @@ namespace YKanBan.Search;
|
|||||||
/// (unbalanced parentheses, dangling or consecutive operators, unterminated
|
/// (unbalanced parentheses, dangling or consecutive operators, unterminated
|
||||||
/// phrases, invalid escapes, a backslash in a bare word, unknown qualifier
|
/// phrases, invalid escapes, a backslash in a bare word, unknown qualifier
|
||||||
/// keys, qualifiers without a value, unquoted values containing ':' or equal
|
/// keys, qualifiers without a value, unquoted values containing ':' or equal
|
||||||
/// to AND/OR, and id values that are not an unquoted positive integer with an
|
/// to AND/OR, id values that are not an unquoted positive integer with an
|
||||||
/// optional '#') raises <see cref="SearchSyntaxException"/>.
|
/// optional '#', and parentheses nested deeper than <see cref="MaxNestingDepth"/>)
|
||||||
|
/// raises <see cref="SearchSyntaxException"/>.
|
||||||
///
|
///
|
||||||
/// Only uppercase AND/OR are operators (lowercase ones are plain words); AND —
|
/// Only uppercase AND/OR are operators (lowercase ones are plain words); AND —
|
||||||
/// explicit or by adjacency — binds tighter than OR; parentheses group. Blank
|
/// explicit or by adjacency — binds tighter than OR; parentheses group. Blank
|
||||||
@@ -18,6 +19,12 @@ namespace YKanBan.Search;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static class SearchQueryParser
|
public static class SearchQueryParser
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Deepest accepted parenthesis nesting. The parser recurses once per level,
|
||||||
|
/// so an unbounded depth would overflow the stack and kill the process.
|
||||||
|
/// </summary>
|
||||||
|
public const int MaxNestingDepth = 64;
|
||||||
|
|
||||||
/// <summary>The recognized qualifier keys; add new entries here to extend the grammar.</summary>
|
/// <summary>The recognized qualifier keys; add new entries here to extend the grammar.</summary>
|
||||||
private static readonly (string Key, QualifierKind Kind)[] QualifierTable =
|
private static readonly (string Key, QualifierKind Kind)[] QualifierTable =
|
||||||
[
|
[
|
||||||
@@ -114,6 +121,7 @@ public static class SearchQueryParser
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
List<SearchToken> tokens = SearchLexer.Tokenize(text).ToList();
|
List<SearchToken> tokens = SearchLexer.Tokenize(text).ToList();
|
||||||
|
EnsureNestingWithinLimit(tokens);
|
||||||
return Query.ParseOrThrow(tokens);
|
return Query.ParseOrThrow(tokens);
|
||||||
}
|
}
|
||||||
catch (ParseException exception)
|
catch (ParseException exception)
|
||||||
@@ -122,6 +130,28 @@ public static class SearchQueryParser
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Rejects parenthesis nesting deeper than <see cref="MaxNestingDepth"/>
|
||||||
|
/// before the recursive parser sees it. Balance itself is left to the parser.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="tokens">The token stream.</param>
|
||||||
|
/// <exception cref="SearchSyntaxException">The nesting is too deep.</exception>
|
||||||
|
private static void EnsureNestingWithinLimit(IEnumerable<SearchToken> tokens)
|
||||||
|
{
|
||||||
|
int depth = 0;
|
||||||
|
foreach (SearchToken token in tokens)
|
||||||
|
{
|
||||||
|
if (token is SearchToken.OpenParen && ++depth > MaxNestingDepth)
|
||||||
|
{
|
||||||
|
throw new SearchSyntaxException($"Parentheses are nested more than {MaxNestingDepth} levels deep.");
|
||||||
|
}
|
||||||
|
if (token is SearchToken.CloseParen && depth > 0)
|
||||||
|
{
|
||||||
|
depth--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#region Atom construction
|
#region Atom construction
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -8,6 +8,15 @@ namespace YKanBan.Search;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class SearchSyntaxException : Exception
|
public sealed class SearchSyntaxException : Exception
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes the exception with a descriptive English message.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="message">The English diagnostic message.</param>
|
||||||
|
public SearchSyntaxException(string message)
|
||||||
|
: base(message)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes the exception with a descriptive English message.
|
/// Initializes the exception with a descriptive English message.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -48,6 +48,20 @@ public sealed class AppServices : IDisposable
|
|||||||
return Session;
|
return Session;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a workspace with its preset columns and opens it, holding
|
||||||
|
/// the lock from the creation of .ykanban onwards.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="folderPath">The existing folder to initialize.</param>
|
||||||
|
/// <returns>The open session.</returns>
|
||||||
|
/// <exception cref="YKanBan.Storage.WorkspaceDirectoryMissingException">The folder does not exist on disk.</exception>
|
||||||
|
/// <exception cref="YKanBan.Storage.WorkspaceLockException">Another instance already holds the lock.</exception>
|
||||||
|
public WorkspaceSession InitializeWorkspace(string folderPath)
|
||||||
|
{
|
||||||
|
Session = WorkspaceSession.Initialize(folderPath);
|
||||||
|
return Session;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Persists the configuration when this session changed a setting; called once at shutdown.
|
/// Persists the configuration when this session changed a setting; called once at shutdown.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -33,16 +33,7 @@ public static class SqliteDatabase
|
|||||||
/// <returns>An open connection with all PRAGMAs applied and the schema migrated.</returns>
|
/// <returns>An open connection with all PRAGMAs applied and the schema migrated.</returns>
|
||||||
public static SqliteConnection Open(string databasePath, IReadOnlyList<SchemaMigration> migrations)
|
public static SqliteConnection Open(string databasePath, IReadOnlyList<SchemaMigration> migrations)
|
||||||
{
|
{
|
||||||
var connection = new SqliteConnection(new SqliteConnectionStringBuilder
|
SqliteConnection connection = OpenConnection(databasePath);
|
||||||
{
|
|
||||||
DataSource = databasePath,
|
|
||||||
Mode = SqliteOpenMode.ReadWriteCreate,
|
|
||||||
|
|
||||||
// Each process holds its own single connection; a pool would only add noise.
|
|
||||||
Pooling = false,
|
|
||||||
}.ToString());
|
|
||||||
|
|
||||||
connection.Open();
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
ApplyPragmas(connection);
|
ApplyPragmas(connection);
|
||||||
@@ -57,6 +48,74 @@ public static class SqliteDatabase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a new database file with the mandatory PRAGMAs, then applies
|
||||||
|
/// every migration and the optional seed in one transaction, so the file
|
||||||
|
/// ends up either fully built and seeded or still at version 0.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="databasePath">Path of the SQLite database file; it must not exist yet.</param>
|
||||||
|
/// <param name="migrations">Contiguous migration list ordered by version, starting at 1.</param>
|
||||||
|
/// <param name="seed">Initial content written in the same transaction, when any.</param>
|
||||||
|
/// <returns>An open connection with all PRAGMAs applied and the schema migrated.</returns>
|
||||||
|
/// <exception cref="ArgumentException">The migration list is not contiguous from version 1.</exception>
|
||||||
|
/// <exception cref="InvalidOperationException">The database file already exists.</exception>
|
||||||
|
public static SqliteConnection Create(
|
||||||
|
string databasePath,
|
||||||
|
IReadOnlyList<SchemaMigration> migrations,
|
||||||
|
Action<SqliteConnection, SqliteTransaction>? seed = null)
|
||||||
|
{
|
||||||
|
ValidateMigrations(migrations);
|
||||||
|
if (File.Exists(databasePath))
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException($"The database already exists: {databasePath}");
|
||||||
|
}
|
||||||
|
|
||||||
|
SqliteConnection connection = OpenConnection(databasePath);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ApplyPragmas(connection);
|
||||||
|
RegisterFunctions(connection);
|
||||||
|
|
||||||
|
using var transaction = connection.BeginTransaction();
|
||||||
|
foreach (SchemaMigration migration in migrations)
|
||||||
|
{
|
||||||
|
Execute(connection, migration.Sql, transaction);
|
||||||
|
Execute(connection, $"PRAGMA user_version={migration.Version};", transaction);
|
||||||
|
}
|
||||||
|
seed?.Invoke(connection, transaction);
|
||||||
|
transaction.Commit();
|
||||||
|
return connection;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
connection.Dispose();
|
||||||
|
|
||||||
|
// Leave no empty version-0 file behind that a later open would migrate into an empty board.
|
||||||
|
DeleteDatabaseFilesBestEffort(databasePath);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Deletes a database file together with its WAL and shared-memory files,
|
||||||
|
/// ignoring failures.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="databasePath">Path of the SQLite database file.</param>
|
||||||
|
private static void DeleteDatabaseFilesBestEffort(string databasePath)
|
||||||
|
{
|
||||||
|
foreach (string path in new[] { databasePath, databasePath + "-wal", databasePath + "-shm", databasePath + "-journal" })
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
File.Delete(path);
|
||||||
|
}
|
||||||
|
catch (Exception exception) when (exception is IOException or UnauthorizedAccessException)
|
||||||
|
{
|
||||||
|
// Best effort: the original failure is what gets reported.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Reads the stored <c>PRAGMA user_version</c> value.
|
/// Reads the stored <c>PRAGMA user_version</c> value.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -105,14 +164,7 @@ public static class SqliteDatabase
|
|||||||
/// <exception cref="SchemaVersionException">The database was written by a newer build.</exception>
|
/// <exception cref="SchemaVersionException">The database was written by a newer build.</exception>
|
||||||
internal static void ApplyMigrations(SqliteConnection connection, IReadOnlyList<SchemaMigration> migrations)
|
internal static void ApplyMigrations(SqliteConnection connection, IReadOnlyList<SchemaMigration> migrations)
|
||||||
{
|
{
|
||||||
// Contract check: the list must be ordered, contiguous and start at version 1.
|
ValidateMigrations(migrations);
|
||||||
for (int index = 0; index < migrations.Count; index++)
|
|
||||||
{
|
|
||||||
if (migrations[index].Version != index + 1)
|
|
||||||
{
|
|
||||||
throw new ArgumentException("Migrations must be contiguous and start at version 1.", nameof(migrations));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
long current = ReadUserVersion(connection);
|
long current = ReadUserVersion(connection);
|
||||||
int latest = migrations.Count;
|
int latest = migrations.Count;
|
||||||
@@ -138,6 +190,42 @@ public static class SqliteDatabase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Opens a connection to the file, creating it if needed, without any configuration.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="databasePath">Path of the SQLite database file.</param>
|
||||||
|
/// <returns>The open connection.</returns>
|
||||||
|
private static SqliteConnection OpenConnection(string databasePath)
|
||||||
|
{
|
||||||
|
var connection = new SqliteConnection(new SqliteConnectionStringBuilder
|
||||||
|
{
|
||||||
|
DataSource = databasePath,
|
||||||
|
Mode = SqliteOpenMode.ReadWriteCreate,
|
||||||
|
|
||||||
|
// Each process holds its own single connection; a pool would only add noise.
|
||||||
|
Pooling = false,
|
||||||
|
}.ToString());
|
||||||
|
|
||||||
|
connection.Open();
|
||||||
|
return connection;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Checks that the migration list is ordered, contiguous and starts at version 1.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="migrations">The migration list.</param>
|
||||||
|
/// <exception cref="ArgumentException">The list breaks the contract.</exception>
|
||||||
|
private static void ValidateMigrations(IReadOnlyList<SchemaMigration> migrations)
|
||||||
|
{
|
||||||
|
for (int index = 0; index < migrations.Count; index++)
|
||||||
|
{
|
||||||
|
if (migrations[index].Version != index + 1)
|
||||||
|
{
|
||||||
|
throw new ArgumentException("Migrations must be contiguous and start at version 1.", nameof(migrations));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Executes a non-query SQL script, optionally inside an explicit transaction.
|
/// Executes a non-query SQL script, optionally inside an explicit transaction.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -61,6 +61,28 @@ public sealed class WorkspaceNotInitializedException : YKanBanException
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Signals that .ykanban exists but its database file does not, so the
|
||||||
|
/// workspace data is missing; a new empty database is never created silently.
|
||||||
|
/// </summary>
|
||||||
|
public sealed class WorkspaceDatabaseMissingException : YKanBanException
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the database file that was expected to exist.
|
||||||
|
/// </summary>
|
||||||
|
public string DatabasePath { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes the exception for a missing workspace database.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="databasePath">The missing database file path.</param>
|
||||||
|
public WorkspaceDatabaseMissingException(string databasePath)
|
||||||
|
: base($"The workspace database is missing: {databasePath}")
|
||||||
|
{
|
||||||
|
DatabasePath = databasePath;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Signals that another instance already holds the workspace lock, so this
|
/// Signals that another instance already holds the workspace lock, so this
|
||||||
/// process must not touch the workspace.
|
/// process must not touch the workspace.
|
||||||
|
|||||||
@@ -3,10 +3,10 @@ using Microsoft.Data.Sqlite;
|
|||||||
namespace YKanBan.Storage.Workspace;
|
namespace YKanBan.Storage.Workspace;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates the .ykanban structure for a folder: the folder itself and an
|
/// Creates the .ykanban structure for a folder in the mandated order: the
|
||||||
/// empty, fully migrated database. Adding preset content is deliberately a
|
/// .ykanban folder, then the exclusive lock, then the database. The database
|
||||||
/// separate concern handled by <see cref="WorkspacePreset"/>, so the
|
/// schema and the optional preset content are written in one transaction, so a
|
||||||
/// database can be created without any rows.
|
/// failure never leaves a half-built database behind.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static class WorkspaceInitializer
|
public static class WorkspaceInitializer
|
||||||
{
|
{
|
||||||
@@ -19,27 +19,50 @@ public static class WorkspaceInitializer
|
|||||||
public static bool IsWorkspace(string folderPath) => Directory.Exists(WorkspacePaths.Root(folderPath));
|
public static bool IsWorkspace(string folderPath) => Directory.Exists(WorkspacePaths.Root(folderPath));
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a fresh workspace: creates .ykanban and an empty migrated
|
/// Initializes a fresh workspace without any preset content and releases
|
||||||
/// database, without adding any preset content.
|
/// the lock again.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="folderPath">The existing folder to initialize.</param>
|
/// <param name="folderPath">The existing folder to initialize.</param>
|
||||||
/// <exception cref="WorkspaceDirectoryMissingException">The folder does not exist on disk.</exception>
|
/// <exception cref="WorkspaceDirectoryMissingException">The folder does not exist on disk.</exception>
|
||||||
|
/// <exception cref="WorkspaceLockException">Another instance holds the workspace lock.</exception>
|
||||||
/// <exception cref="InvalidOperationException">The workspace database already exists.</exception>
|
/// <exception cref="InvalidOperationException">The workspace database already exists.</exception>
|
||||||
public static void Initialize(string folderPath)
|
public static void Initialize(string folderPath)
|
||||||
|
{
|
||||||
|
using WorkspaceLock workspaceLock = InitializeLocked(folderPath, addPresetColumns: false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a fresh workspace and returns the lock still held, so the
|
||||||
|
/// caller can open the workspace without ever releasing it.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="folderPath">The existing folder to initialize.</param>
|
||||||
|
/// <param name="addPresetColumns">Whether to add the preset columns in the schema transaction.</param>
|
||||||
|
/// <returns>The held workspace lock.</returns>
|
||||||
|
/// <exception cref="WorkspaceDirectoryMissingException">The folder does not exist on disk.</exception>
|
||||||
|
/// <exception cref="WorkspaceLockException">Another instance holds the workspace lock.</exception>
|
||||||
|
/// <exception cref="InvalidOperationException">The workspace database already exists.</exception>
|
||||||
|
internal static WorkspaceLock InitializeLocked(string folderPath, bool addPresetColumns)
|
||||||
{
|
{
|
||||||
if (!Directory.Exists(folderPath))
|
if (!Directory.Exists(folderPath))
|
||||||
{
|
{
|
||||||
throw new WorkspaceDirectoryMissingException(folderPath);
|
throw new WorkspaceDirectoryMissingException(folderPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
string databasePath = WorkspacePaths.Database(folderPath);
|
// .ykanban first: the lock file lives inside it.
|
||||||
if (File.Exists(databasePath))
|
|
||||||
{
|
|
||||||
throw new InvalidOperationException($"The workspace database already exists: {databasePath}");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create the .ykanban folder, then the migrated but still empty database.
|
|
||||||
Directory.CreateDirectory(WorkspacePaths.Root(folderPath));
|
Directory.CreateDirectory(WorkspacePaths.Root(folderPath));
|
||||||
using SqliteConnection connection = SqliteDatabase.Open(databasePath, WorkspaceSchema.Migrations);
|
WorkspaceLock workspaceLock = WorkspaceLock.Acquire(folderPath);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using SqliteConnection connection = SqliteDatabase.Create(
|
||||||
|
WorkspacePaths.Database(folderPath),
|
||||||
|
WorkspaceSchema.Migrations,
|
||||||
|
addPresetColumns ? WorkspacePreset.AddPresetColumns : null);
|
||||||
|
return workspaceLock;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
workspaceLock.Dispose();
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -12,15 +12,14 @@ public static class WorkspacePreset
|
|||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Inserts the three preset columns (the current language's equivalents of
|
/// Inserts the three preset columns (the current language's equivalents of
|
||||||
/// To Do / In Progress / Done) in a single transaction.
|
/// To Do / In Progress / Done) inside the caller's transaction, so the
|
||||||
|
/// presets land together with the schema or not at all.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="folderPath">The initialized workspace folder.</param>
|
/// <param name="connection">The connection to the freshly created database.</param>
|
||||||
/// <exception cref="SqliteException">The workspace database does not exist or a title collides with an existing column.</exception>
|
/// <param name="transaction">The transaction that also builds the schema.</param>
|
||||||
public static void AddPresetColumns(string folderPath)
|
/// <exception cref="SqliteException">A title collides with an existing column.</exception>
|
||||||
|
public static void AddPresetColumns(SqliteConnection connection, SqliteTransaction transaction)
|
||||||
{
|
{
|
||||||
using SqliteConnection connection = SqliteDatabase.Open(
|
|
||||||
WorkspacePaths.Database(folderPath), WorkspaceSchema.Migrations);
|
|
||||||
|
|
||||||
long now = UnixTime.Now;
|
long now = UnixTime.Now;
|
||||||
|
|
||||||
// Preset titles are data at creation time: whatever the current language says gets stored.
|
// Preset titles are data at creation time: whatever the current language says gets stored.
|
||||||
@@ -31,8 +30,6 @@ public static class WorkspacePreset
|
|||||||
Resources.PresetColumn_Done,
|
Resources.PresetColumn_Done,
|
||||||
];
|
];
|
||||||
|
|
||||||
// Insert all three atomically so a partially populated workspace can never exist.
|
|
||||||
using var transaction = connection.BeginTransaction();
|
|
||||||
foreach (string title in titles)
|
foreach (string title in titles)
|
||||||
{
|
{
|
||||||
using var command = connection.CreateCommand();
|
using var command = connection.CreateCommand();
|
||||||
@@ -45,6 +42,5 @@ public static class WorkspacePreset
|
|||||||
command.Parameters.AddWithValue("$now", now);
|
command.Parameters.AddWithValue("$now", now);
|
||||||
command.ExecuteNonQuery();
|
command.ExecuteNonQuery();
|
||||||
}
|
}
|
||||||
transaction.Commit();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -41,9 +41,43 @@ public sealed class WorkspaceSession : IDisposable
|
|||||||
/// <returns>The opened session; dispose it to release the lock and connection.</returns>
|
/// <returns>The opened session; dispose it to release the lock and connection.</returns>
|
||||||
/// <exception cref="WorkspaceNotInitializedException">The folder has no .ykanban structure.</exception>
|
/// <exception cref="WorkspaceNotInitializedException">The folder has no .ykanban structure.</exception>
|
||||||
/// <exception cref="WorkspaceLockException">Another instance already holds the lock.</exception>
|
/// <exception cref="WorkspaceLockException">Another instance already holds the lock.</exception>
|
||||||
|
/// <exception cref="WorkspaceDatabaseMissingException">.ykanban exists but its database file does not.</exception>
|
||||||
public static WorkspaceSession Open(string folderPath)
|
public static WorkspaceSession Open(string folderPath)
|
||||||
{
|
{
|
||||||
WorkspaceLock workspaceLock = WorkspaceLock.Acquire(folderPath);
|
WorkspaceLock workspaceLock = WorkspaceLock.Acquire(folderPath);
|
||||||
|
|
||||||
|
// Opening would otherwise create an empty database and show an empty board as if nothing was lost.
|
||||||
|
string databasePath = WorkspacePaths.Database(folderPath);
|
||||||
|
if (!File.Exists(databasePath))
|
||||||
|
{
|
||||||
|
workspaceLock.Dispose();
|
||||||
|
throw new WorkspaceDatabaseMissingException(databasePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
return OpenLocked(folderPath, workspaceLock);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a workspace with its preset columns and opens it. The lock
|
||||||
|
/// is taken right after .ykanban is created and is never released in
|
||||||
|
/// between, so no other instance can interleave with the initialization.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="folderPath">The existing folder to initialize.</param>
|
||||||
|
/// <returns>The opened session; dispose it to release the lock and connection.</returns>
|
||||||
|
/// <exception cref="WorkspaceDirectoryMissingException">The folder does not exist on disk.</exception>
|
||||||
|
/// <exception cref="WorkspaceLockException">Another instance holds the workspace lock.</exception>
|
||||||
|
/// <exception cref="InvalidOperationException">The workspace database already exists.</exception>
|
||||||
|
public static WorkspaceSession Initialize(string folderPath) =>
|
||||||
|
OpenLocked(folderPath, WorkspaceInitializer.InitializeLocked(folderPath, addPresetColumns: true));
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Opens the repository under an already held lock; the lock is released if that fails.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="folderPath">The workspace folder.</param>
|
||||||
|
/// <param name="workspaceLock">The held workspace lock.</param>
|
||||||
|
/// <returns>The opened session.</returns>
|
||||||
|
private static WorkspaceSession OpenLocked(string folderPath, WorkspaceLock workspaceLock)
|
||||||
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var repository = new WorkspaceRepository(folderPath);
|
var repository = new WorkspaceRepository(folderPath);
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ namespace YKanBan.ViewModels.ErrorPages;
|
|||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The full-window page shown when a workspace cannot be opened or initialized:
|
/// The full-window page shown when a workspace cannot be opened or initialized:
|
||||||
/// a schema newer than this build, an unopenable or damaged database, an I/O or
|
/// a schema newer than this build, a missing, unopenable or damaged database, an I/O or
|
||||||
/// permission error, or any unrecognized failure. It shows a localized message
|
/// permission error, or any unrecognized failure. It shows a localized message
|
||||||
/// chosen by exception type plus the read-only, copyable English exception
|
/// chosen by exception type plus the read-only, copyable English exception
|
||||||
/// details, and has no operations.
|
/// details, and has no operations.
|
||||||
@@ -55,6 +55,7 @@ public sealed class OpenFailedPageViewModel : ViewModelBase
|
|||||||
{
|
{
|
||||||
SchemaVersionException schema => string.Format(
|
SchemaVersionException schema => string.Format(
|
||||||
culture, Resources.Error_OpenFailed_SchemaTooNew, folderPath, schema.StoredVersion, schema.SupportedVersion),
|
culture, Resources.Error_OpenFailed_SchemaTooNew, folderPath, schema.StoredVersion, schema.SupportedVersion),
|
||||||
|
WorkspaceDatabaseMissingException => string.Format(culture, Resources.Error_OpenFailed_DatabaseMissing, folderPath),
|
||||||
SqliteException => string.Format(culture, Resources.Error_OpenFailed_Database, folderPath),
|
SqliteException => string.Format(culture, Resources.Error_OpenFailed_Database, folderPath),
|
||||||
UnauthorizedAccessException => string.Format(culture, Resources.Error_OpenFailed_AccessDenied, folderPath),
|
UnauthorizedAccessException => string.Format(culture, Resources.Error_OpenFailed_AccessDenied, folderPath),
|
||||||
IOException => string.Format(culture, Resources.Error_OpenFailed_Io, folderPath),
|
IOException => string.Format(culture, Resources.Error_OpenFailed_Io, folderPath),
|
||||||
|
|||||||
@@ -105,15 +105,21 @@ public sealed partial class MainWindowViewModel : ViewModelBase
|
|||||||
/// Opens the workspace and switches the content to the normal view.
|
/// Opens the workspace and switches the content to the normal view.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="folderPath">The workspace folder to open.</param>
|
/// <param name="folderPath">The workspace folder to open.</param>
|
||||||
private void OpenWorkspace(string folderPath)
|
private void OpenWorkspace(string folderPath) => ShowWorkspace(folderPath, _services.OpenWorkspace(folderPath));
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Switches the content to the normal view of an opened workspace.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="folderPath">The workspace folder.</param>
|
||||||
|
/// <param name="session">The opened workspace session.</param>
|
||||||
|
private void ShowWorkspace(string folderPath, WorkspaceSession session)
|
||||||
{
|
{
|
||||||
WorkspaceSession session = _services.OpenWorkspace(folderPath);
|
|
||||||
Content = new WorkspaceViewModel(session, ShowSettings, ShowAbout, _services.Config, _dialogs);
|
Content = new WorkspaceViewModel(session, ShowSettings, ShowAbout, _services.Config, _dialogs);
|
||||||
Title = $"{new DirectoryInfo(folderPath).Name} - {Resources.App_Name}";
|
Title = $"{new DirectoryInfo(folderPath).Name} - {Resources.App_Name}";
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes the folder shown by the not-initialized page, adds the preset
|
/// Initializes the folder shown by the not-initialized page with its preset
|
||||||
/// columns and opens the resulting workspace.
|
/// columns and opens the resulting workspace.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>A completed task once initialization has been attempted.</returns>
|
/// <returns>A completed task once initialization has been attempted.</returns>
|
||||||
@@ -126,9 +132,12 @@ public sealed partial class MainWindowViewModel : ViewModelBase
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
WorkspaceInitializer.Initialize(page.FolderPath);
|
ShowWorkspace(page.FolderPath, _services.InitializeWorkspace(page.FolderPath));
|
||||||
WorkspacePreset.AddPresetColumns(page.FolderPath);
|
}
|
||||||
OpenWorkspace(page.FolderPath);
|
catch (WorkspaceLockException)
|
||||||
|
{
|
||||||
|
// Another instance got there first and holds the workspace: same page as at startup.
|
||||||
|
Content = new LockConflictPageViewModel(page.FolderPath);
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
{
|
{
|
||||||
|
|||||||
+5
-4
@@ -14,7 +14,7 @@
|
|||||||
### A1 语言切换重启生效
|
### A1 语言切换重启生效
|
||||||
|
|
||||||
- [ ] 设置 → 语言改为简体中文 → 显示"重启后生效"提示;当前界面**不**变化
|
- [ ] 设置 → 语言改为简体中文 → 显示"重启后生效"提示;当前界面**不**变化
|
||||||
- [ ] 确认关闭后,退出程序 → `app.json` 中 `Language` 为 `zh-Hans`
|
- [ ] 确认关闭后,退出程序 → `app.json` 中 `"language"` 为 `"zh-Hans"`
|
||||||
- [ ] 重启 → 全部界面文本(顶部区、两个 tab、各模态、错误页、排序项、确认对话框)为中文,无残留英文硬编码
|
- [ ] 重启 → 全部界面文本(顶部区、两个 tab、各模态、错误页、排序项、确认对话框)为中文,无残留英文硬编码
|
||||||
- [ ] 切回英文 → 重启后恢复英文
|
- [ ] 切回英文 → 重启后恢复英文
|
||||||
- [ ] 中文下新初始化的工作区预置列为 待办 / 进行中 / 已完成;切回英文后这些列名**不变**(已是数据)
|
- [ ] 中文下新初始化的工作区预置列为 待办 / 进行中 / 已完成;切回英文后这些列名**不变**(已是数据)
|
||||||
@@ -42,11 +42,11 @@
|
|||||||
- [ ] 打开两个实例,只在实例 1 改设置;先关实例 1,再关**未改过设置**的实例 2 → `app.json` 保持实例 1 写入的内容(未改设置的实例不写盘)
|
- [ ] 打开两个实例,只在实例 1 改设置;先关实例 1,再关**未改过设置**的实例 2 → `app.json` 保持实例 1 写入的内容(未改设置的实例不写盘)
|
||||||
- [ ] 处于错误页(例如参数错误页)的实例退出时不写 `app.json`(可先删除 `app.json`,退出后确认文件未被创建)
|
- [ ] 处于错误页(例如参数错误页)的实例退出时不写 `app.json`(可先删除 `app.json`,退出后确认文件未被创建)
|
||||||
- [ ] `app.json` 写成非法 JSON → 启动正常、使用默认值,生成 `app.json.bak`;改一次设置退出后 `app.json` 恢复为合法内容
|
- [ ] `app.json` 写成非法 JSON → 启动正常、使用默认值,生成 `app.json.bak`;改一次设置退出后 `app.json` 恢复为合法内容
|
||||||
- [ ] `app.json` 中单个字段非法(如 `"Theme": "pink"`、列宽 `9999`)→ 仅该字段回退默认,其余设置保留,不生成 `.bak`
|
- [ ] `app.json` 中单个字段非法(如 `"theme": "pink"`、列宽 `"custom-pixels": 9999`)→ 仅该字段回退默认,其余设置保留,不生成 `.bak`
|
||||||
|
|
||||||
## B. 启动与错误页(M4 / M4R)
|
## B. 启动与错误页(M4 / M4R)
|
||||||
|
|
||||||
- [ ] 无参数、两个参数、`--help`、`-x`、空字符串参数 → 参数错误页,显示 `Usage: ykanban <path>`
|
- [ ] 无参数、两个参数、`--help`、`-x`、空字符串参数、纯空格参数 → 参数错误页,显示 `Usage: ykanban <path>`
|
||||||
- [ ] 不存在的路径、指向文件的路径 → 目录不存在页
|
- [ ] 不存在的路径、指向文件的路径 → 目录不存在页
|
||||||
- [ ] 相对路径(如 `ykanban .`)按当前目录解析
|
- [ ] 相对路径(如 `ykanban .`)按当前目录解析
|
||||||
- [ ] 无 `.ykanban` 的文件夹 → 未初始化页;点"初始化"后进入看板,预置三列
|
- [ ] 无 `.ykanban` 的文件夹 → 未初始化页;点"初始化"后进入看板,预置三列
|
||||||
@@ -54,6 +54,7 @@
|
|||||||
- [ ] 同一工作区开第二个实例 → 锁冲突页,无任何操作按钮;关闭第一个实例后可正常打开
|
- [ ] 同一工作区开第二个实例 → 锁冲突页,无任何操作按钮;关闭第一个实例后可正常打开
|
||||||
- [ ] 工作区数据库 `user_version` 改为更高值 → 打开失败页,提示版本过新,英文详情可选中复制
|
- [ ] 工作区数据库 `user_version` 改为更高值 → 打开失败页,提示版本过新,英文详情可选中复制
|
||||||
- [ ] 把 `ykanban.db` 换成垃圾内容 → 打开失败页(数据库无法打开/损坏)
|
- [ ] 把 `ykanban.db` 换成垃圾内容 → 打开失败页(数据库无法打开/损坏)
|
||||||
|
- [ ] 关闭程序后删除 `.ykanban/ykanban.db`(及 -wal / -shm)→ 打开失败页,提示数据库缺失;`.ykanban` 中**不会**出现新建的空库
|
||||||
- [ ] 窗口标题:正常时 `工作区名 - YKanBan`,错误页时仅 `YKanBan`
|
- [ ] 窗口标题:正常时 `工作区名 - YKanBan`,错误页时仅 `YKanBan`
|
||||||
- [ ] 顶部区:工作区名 + 小一号完整路径;右侧 导出 / 设置 / 关于 同排
|
- [ ] 顶部区:工作区名 + 小一号完整路径;右侧 导出 / 设置 / 关于 同排
|
||||||
|
|
||||||
@@ -98,5 +99,5 @@
|
|||||||
- [ ] 产物:`YKanBan-<版本>-win-x64.zip`、`-linux-x64.tar.gz`、`-osx-x64.tar.gz`、`-osx-arm64.tar.gz`
|
- [ ] 产物:`YKanBan-<版本>-win-x64.zip`、`-linux-x64.tar.gz`、`-osx-x64.tar.gz`、`-osx-arm64.tar.gz`
|
||||||
- [ ] Windows:解压后 `YKanBan.exe <path>` 可直接运行(自包含,无需安装 .NET)
|
- [ ] Windows:解压后 `YKanBan.exe <path>` 可直接运行(自包含,无需安装 .NET)
|
||||||
- [ ] Linux:解压后 `./YKanBan <path>` 可运行(可执行位保留)
|
- [ ] Linux:解压后 `./YKanBan <path>` 可运行(可执行位保留)
|
||||||
- [ ] macOS:解除隔离后 `open -a YKanBan --args <path>` 与直接运行包内可执行文件均可用;双击 `.app` 只显示参数错误页
|
- [ ] macOS:解除隔离后 `open -n -a YKanBan --args <绝对路径>` 与直接运行包内可执行文件均可用;双击 `.app` 只显示参数错误页
|
||||||
- [ ] 故意让某平台测试失败 → 该 RID 无产物,其余 RID 不受影响
|
- [ ] 故意让某平台测试失败 → 该 RID 无产物,其余 RID 不受影响
|
||||||
+12
-7
@@ -16,6 +16,7 @@
|
|||||||
- 网络共享明确不支持;命令行参数边界;macOS 无参启动行为写入文档(§2.3、§4.1、附录)
|
- 网络共享明确不支持;命令行参数边界;macOS 无参启动行为写入文档(§2.3、§4.1、附录)
|
||||||
- 补充:导出转义规则、卡片列表虚拟化、模态窗口 FlowDirection、`Resources` 类名使用规则、CI osx-x64 运行器(§5、§7、§8)
|
- 补充:导出转义规则、卡片列表虚拟化、模态窗口 FlowDirection、`Resources` 类名使用规则、CI osx-x64 运行器(§5、§7、§8)
|
||||||
- 依赖:Avalonia 11.3.6 → 11.3.22,Semi.Avalonia 11.2.1.10 → 11.3.22(§7)
|
- 依赖:Avalonia 11.3.6 → 11.3.22,Semi.Avalonia 11.2.1.10 → 11.3.22(§7)
|
||||||
|
- 实现回补:搜索括号嵌套上限 64 层,空短语、短语紧贴文本、`key:` 后空白均为非法(§6.1、§6.2);导出表格单元格转义 `\`(§5.8);初始化中途锁冲突进锁冲突页、数据库文件缺失不静默新建(§4.4)
|
||||||
- 里程碑:标注 M0–M4 已完成,新增 **M4R(v1.9 回补)**(§9)
|
- 里程碑:标注 M0–M4 已完成,新增 **M4R(v1.9 回补)**(§9)
|
||||||
|
|
||||||
## 1. 项目概述
|
## 1. 项目概述
|
||||||
@@ -122,7 +123,7 @@ card_tags: (card_id, tag_id) 复合主键,双向 ON DELETE CASCADE
|
|||||||
- 恰好一个位置参数为合法;相对路径以进程当前工作目录解析为绝对路径
|
- 恰好一个位置参数为合法;相对路径以进程当前工作目录解析为绝对路径
|
||||||
- 无参数、多于一个参数、或参数以 `-` 开头(含 `--help` 等任何选项形式)→ **参数错误页**
|
- 无参数、多于一个参数、或参数以 `-` 开头(含 `--help` 等任何选项形式)→ **参数错误页**
|
||||||
- 路径不存在或存在但不是目录 → 目录不存在页
|
- 路径不存在或存在但不是目录 → 目录不存在页
|
||||||
- macOS 双击 `.app` 时无参数,只会显示参数错误页——已接受(纯命令行定位);USAGE.md 说明 macOS 启动方式(`open -a YKanBan --args <path>` 或直接运行包内可执行文件)
|
- macOS 双击 `.app` 时无参数,只会显示参数错误页——已接受(纯命令行定位);USAGE.md 说明 macOS 启动方式:`open -n -a YKanBan --args <绝对路径>` 或直接运行包内可执行文件(`-n` 保证已有实例运行时仍另起实例;经 `open` 启动时当前目录为 `/`,故须绝对路径)
|
||||||
- 窗口标题:`工作区名 - YKanBan`;无有效工作区(错误页状态)时仅 `YKanBan`
|
- 窗口标题:`工作区名 - YKanBan`;无有效工作区(错误页状态)时仅 `YKanBan`
|
||||||
|
|
||||||
### 4.2 连接管理
|
### 4.2 连接管理
|
||||||
@@ -151,10 +152,11 @@ card_tags: (card_id, tag_id) 复合主键,双向 ON DELETE CASCADE
|
|||||||
| 参数错误页 | 参数不合法(见 §4.1) | 参数错误提示 + 正确用法说明(`ykanban <path>`) |
|
| 参数错误页 | 参数不合法(见 §4.1) | 参数错误提示 + 正确用法说明(`ykanban <path>`) |
|
||||||
| 目录不存在页 | 参数路径不存在或不是目录 | 提示 |
|
| 目录不存在页 | 参数路径不存在或不是目录 | 提示 |
|
||||||
| 未初始化页 | 路径存在但无 `.ykanban` | 提示 + 初始化按钮(唯一带操作的错误页) |
|
| 未初始化页 | 路径存在但无 `.ykanban` | 提示 + 初始化按钮(唯一带操作的错误页) |
|
||||||
| 锁冲突页 | 锁文件被占用 | 仅提示,无任何操作 |
|
| 锁冲突页 | 锁文件被占用(含点击初始化时锁已被其他实例抢先持有) | 仅提示,无任何操作 |
|
||||||
| 工作区打开失败页 | schema 版本高于程序支持版本;数据库无法打开/损坏;IO 或权限错误(含初始化失败) | 按异常类型显示本地化提示 + 只读可复制的英文异常详情;无其他操作 |
|
| 工作区打开失败页 | schema 版本高于程序支持版本;`.ykanban` 存在但 `ykanban.db` 缺失;数据库无法打开/损坏;IO 或权限错误(含初始化失败) | 按异常类型显示本地化提示 + 只读可复制的英文异常详情;无其他操作 |
|
||||||
|
|
||||||
- 未初始化页点击初始化失败 → 切换至工作区打开失败页
|
- 未初始化页点击初始化失败 → 切换至工作区打开失败页;例外:失败原因为锁冲突(其他实例抢先持有锁)→ 切换至锁冲突页
|
||||||
|
- `.ykanban` 存在但 `ykanban.db` 缺失 → 工作区打开失败页,提示从备份恢复或删除 `.ykanban` 后重新初始化;**绝不静默新建空库**
|
||||||
- 未被识别的异常类型归入工作区打开失败页的通用提示
|
- 未被识别的异常类型归入工作区打开失败页的通用提示
|
||||||
|
|
||||||
正常视图 = 顶部显示区域 + TabControl(见 §5)。
|
正常视图 = 顶部显示区域 + TabControl(见 §5)。
|
||||||
@@ -244,7 +246,7 @@ card_tags: (card_id, tag_id) 复合主键,双向 ON DELETE CASCADE
|
|||||||
- 空列也保留(体现看板结构);无标题卡片以 `### #61` 呈现
|
- 空列也保留(体现看板结构);无标题卡片以 `### #61` 呈现
|
||||||
- 转义规则:
|
- 转义规则:
|
||||||
- 标签名以行内代码呈现,定界反引号数量 = 名称内最长连续反引号串长度 + 1(名称以反引号开头/结尾时两侧加空格)
|
- 标签名以行内代码呈现,定界反引号数量 = 名称内最长连续反引号串长度 + 1(名称以反引号开头/结尾时两侧加空格)
|
||||||
- 标签总表单元格内 `|` → `\|`,换行 → `<br>`
|
- 标签总表单元格内 `\` → `\\`(先于 `|` 处理,否则 `a\|b` 中的 `|` 会被当成列分隔符),`|` → `\|`,换行 → `<br>`
|
||||||
- 卡片正文与列 description **原样输出**(接受其中 Markdown 结构干扰文档层级,已接受)
|
- 卡片正文与列 description **原样输出**(接受其中 Markdown 结构干扰文档层级,已接受)
|
||||||
|
|
||||||
### 5.9 主题(亮 / 暗 / 跟随系统)
|
### 5.9 主题(亮 / 暗 / 跟随系统)
|
||||||
@@ -277,10 +279,11 @@ key := tag | title | content | id | column
|
|||||||
value := word | phrase (tag/title/content/column)
|
value := word | phrase (tag/title/content/column)
|
||||||
| '#'? digit+ (id:十进制正整数,可带前缀 #)
|
| '#'? digit+ (id:十进制正整数,可带前缀 #)
|
||||||
word := 一个或多个字符,不含空白及 ( ) " : \ ;且不等于 AND / OR
|
word := 一个或多个字符,不含空白及 ( ) " : \ ;且不等于 AND / OR
|
||||||
phrase := '"' 任意文本 '"' (内部支持转义:\" → 字面引号,\\ → 字面反斜杠)
|
phrase := '"' 一个或多个字符 '"' (内部支持转义:\" → 字面引号,\\ → 字面反斜杠)
|
||||||
```
|
```
|
||||||
|
|
||||||
- 裸词中出现 `:` 时其左侧必须是合法 key,否则为"未知限定符"错误;含 `:` `(` `)` `\` 等字符的搜索值须用引号(如 `"http://x"`)
|
- 裸词中出现 `:` 时其左侧必须是合法 key,否则为"未知限定符"错误;含 `:` `(` `)` `\` 等字符的搜索值须用引号(如 `"http://x"`)
|
||||||
|
- 短语不得为空(`""`);短语与相邻裸词/短语之间须有空白或括号(`a"b"`、`"a"b`、`"a""b"` 非法),唯一例外是紧贴 key 的限定符值 `key:"…"`;`key:` 与短语值之间不得有空白(`tag: "x"` 非法)
|
||||||
|
|
||||||
### 6.2 语义
|
### 6.2 语义
|
||||||
|
|
||||||
@@ -291,9 +294,11 @@ phrase := '"' 任意文本 '"' (内部支持转义:\" → 字面引号,
|
|||||||
- 短语内部转义:`\"` → 字面引号,`\\` → 字面反斜杠;搜索含空格/保留字符/字面 `AND` 等特殊标签名时,用(必要时转义的)引号值(写入文档)
|
- 短语内部转义:`\"` → 字面引号,`\\` → 字面反斜杠;搜索含空格/保留字符/字面 `AND` 等特殊标签名时,用(必要时转义的)引号值(写入文档)
|
||||||
- **严格校验**:非法表达式弹出错误对话框,不执行搜索。非法集合:
|
- **严格校验**:非法表达式弹出错误对话框,不执行搜索。非法集合:
|
||||||
- 括号不配对
|
- 括号不配对
|
||||||
|
- 括号嵌套超过 64 层(防止递归解析栈溢出;顺序并列的括号组不计入深度)
|
||||||
- 运算符悬空(`bug AND`)、连续运算符(`a AND OR b`)
|
- 运算符悬空(`bug AND`)、连续运算符(`a AND OR b`)
|
||||||
- 限定符无值(`tag:`)、限定符值为裸 `AND`/`OR`(`tag:AND`,须写 `tag:"AND"`)
|
- 限定符无值(`tag:`)、限定符值为裸 `AND`/`OR`(`tag:AND`,须写 `tag:"AND"`)
|
||||||
- 短语引号未闭合、无效转义(`tag:"a\x"`)、裸词中出现 `\`
|
- 短语引号未闭合、无效转义(`tag:"a\x"`)、裸词中出现 `\`
|
||||||
|
- 空短语(`""`、`tag:""`);短语紧贴其他文本(`a"b"`、`"a"b`);`key:` 与短语值之间有空白(`tag: "x"`)
|
||||||
- 未知限定符 key(合法 key 仅 tag / title / content / id / column)
|
- 未知限定符 key(合法 key 仅 tag / title / content / id / column)
|
||||||
- `id:` 值不是十进制正整数(`id:abc`、`id:0`、`id:"61"`)
|
- `id:` 值不是十进制正整数(`id:abc`、`id:0`、`id:"61"`)
|
||||||
- 错误对话框:模态、父窗口居中;文案 = 资源模板"查询表达式有误,详情:{0}"(i18n),{0} 处拼接解析器返回的**非 i18n 英文错误描述串**(对位置信息无要求)
|
- 错误对话框:模态、父窗口居中;文案 = 资源模板"查询表达式有误,详情:{0}"(i18n),{0} 处拼接解析器返回的**非 i18n 英文错误描述串**(对位置信息无要求)
|
||||||
@@ -398,4 +403,4 @@ phrase := '"' 任意文本 '"' (内部支持转义:\" → 字面引号,
|
|||||||
2. 备份/迁移必须同时复制 `ykanban.db`、`ykanban.db-wal`、`ykanban.db-shm` 三个文件;不支持将工作区放在网络共享(SMB/NFS)上
|
2. 备份/迁移必须同时复制 `ykanban.db`、`ykanban.db-wal`、`ykanban.db-shm` 三个文件;不支持将工作区放在网络共享(SMB/NFS)上
|
||||||
3. 搜索语法全文(文法、语义、`word` 字符集、转义规则、保留字、大小写折叠、严格校验与非法表达式清单、错误对话框行为,见 §6)
|
3. 搜索语法全文(文法、语义、`word` 字符集、转义规则、保留字、大小写折叠、严格校验与非法表达式清单、错误对话框行为,见 §6)
|
||||||
4. 命令行启动规则(`ykanban <path>`;参数规则与各错误页,见 §4.1)
|
4. 命令行启动规则(`ykanban <path>`;参数规则与各错误页,见 §4.1)
|
||||||
5. macOS 启动方式(`open -a YKanBan --args <path>` 或直接运行包内可执行文件;双击 `.app` 只会显示参数错误页)
|
5. macOS 启动方式(`open -n -a YKanBan --args <绝对路径>` 或直接运行包内可执行文件;`-n` 保证另起实例,`open` 启动时当前目录为 `/` 故须绝对路径;双击 `.app` 只会显示参数错误页)
|
||||||
+16
-6
@@ -5,7 +5,7 @@
|
|||||||
#
|
#
|
||||||
# win-x64 -> YKanBan-<version>-win-x64.zip (folder YKanBan-<version>-win-x64/)
|
# win-x64 -> YKanBan-<version>-win-x64.zip (folder YKanBan-<version>-win-x64/)
|
||||||
# linux-x64 -> YKanBan-<version>-linux-x64.tar.gz (folder YKanBan-<version>-linux-x64/)
|
# linux-x64 -> YKanBan-<version>-linux-x64.tar.gz (folder YKanBan-<version>-linux-x64/)
|
||||||
# osx-* -> YKanBan-<version>-<rid>.tar.gz (YKanBan.app bundle, ad-hoc signed when codesign exists)
|
# osx-* -> YKanBan-<version>-<rid>.tar.gz (YKanBan.app bundle, ad-hoc signed when possible)
|
||||||
#
|
#
|
||||||
# tar.gz keeps the executable bit, which a plain zip artifact upload would lose.
|
# tar.gz keeps the executable bit, which a plain zip artifact upload would lose.
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
@@ -28,9 +28,15 @@ trap 'rm -rf "$staging"' EXIT
|
|||||||
case "$rid" in
|
case "$rid" in
|
||||||
win-*)
|
win-*)
|
||||||
cp -R "$publish_dir" "$staging/$name"
|
cp -R "$publish_dir" "$staging/$name"
|
||||||
# Compress-Archive is available on every Windows host, unlike zip.
|
rm -f "$output_dir/$name.zip"
|
||||||
powershell -NoProfile -Command \
|
# 7-Zip ships on the Windows runners and writes '/' entry separators;
|
||||||
"Compress-Archive -Path '$(cygpath -w "$staging/$name" 2>/dev/null || echo "$staging/$name")' -DestinationPath '$(cygpath -w "$output_dir/$name.zip" 2>/dev/null || echo "$output_dir/$name.zip")' -Force"
|
# Windows PowerShell 5.1's Compress-Archive writes '\', which breaks
|
||||||
|
# extraction outside Windows.
|
||||||
|
if ! command -v 7z > /dev/null 2>&1; then
|
||||||
|
echo "7z not found" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
(cd "$staging" && 7z a -tzip -bso0 -bsp0 "$output_dir/$name.zip" "$name")
|
||||||
;;
|
;;
|
||||||
linux-*)
|
linux-*)
|
||||||
cp -R "$publish_dir" "$staging/$name"
|
cp -R "$publish_dir" "$staging/$name"
|
||||||
@@ -44,8 +50,12 @@ case "$rid" in
|
|||||||
chmod +x "$app/Contents/MacOS/YKanBan"
|
chmod +x "$app/Contents/MacOS/YKanBan"
|
||||||
sed "s/@VERSION@/${version}/g" "$script_dir/macos/Info.plist" > "$app/Contents/Info.plist"
|
sed "s/@VERSION@/${version}/g" "$script_dir/macos/Info.plist" > "$app/Contents/Info.plist"
|
||||||
if command -v codesign > /dev/null 2>&1; then
|
if command -v codesign > /dev/null 2>&1; then
|
||||||
# Ad-hoc signature: unsigned arm64 code does not run at all.
|
# Ad-hoc signature for the bundle. Not fatal: the SDK already ad-hoc
|
||||||
codesign --force --deep --sign - "$app"
|
# signs the apphost, which is all arm64 needs to run, and --deep may
|
||||||
|
# trip over the non-Mach-O files in Contents/MacOS.
|
||||||
|
if ! codesign --force --deep --sign - "$app"; then
|
||||||
|
echo "warning: ad-hoc signing of YKanBan.app failed; packing it unsigned" >&2
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
tar -C "$staging" -czf "$output_dir/$name.tar.gz" YKanBan.app
|
tar -C "$staging" -czf "$output_dir/$name.tar.gz" YKanBan.app
|
||||||
;;
|
;;
|
||||||
|
|||||||
Reference in new issue
Block a user