Skip to content

Commit

Permalink
Merge pull request #5 from Teajey/1-unhandled-watch-event-accessclose…
Browse files Browse the repository at this point in the history
…write

Test file monitoring
  • Loading branch information
Teajey authored Nov 30, 2023
2 parents 88de3c4 + dea96fb commit 17ca5a6
Show file tree
Hide file tree
Showing 9 changed files with 504 additions and 265 deletions.
60 changes: 60 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Rust

on:
push:
branches: ["main"]
pull_request:
branches: ["main"]

env:
CARGO_TERM_COLOR: always
RUSTFLAGS: "-Dwarnings"

jobs:
build:
runs-on: ubuntu-20.04

steps:
- uses: actions/checkout@v3
- name: Cache
uses: actions/[email protected]
with:
path: |
~/.cargo
target
key: build-${{ runner.os }}
restore-keys: |
build-${{ runner.os }}
- run: cargo build
lint:
needs: build
runs-on: ubuntu-20.04

steps:
- uses: actions/checkout@v3
- name: Cache
uses: actions/[email protected]
with:
path: |
~/.cargo
target
key: build-${{ runner.os }}
restore-keys: |
build-${{ runner.os }}
- run: cargo clippy --all-targets
test:
needs: build
runs-on: ubuntu-20.04

steps:
- uses: actions/checkout@v3
- name: Cache
uses: actions/[email protected]
with:
path: |
~/.cargo
target
key: build-${{ runner.os }}
restore-keys: |
build-${{ runner.os }}
- run: cargo test
30 changes: 30 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@ repository = "https://github.com/Teajey/custard"
[dependencies]
anyhow = "1.0.75"
axum = "0.6.20"
camino = "1.1.6"
chrono = { version = "0.4.31", features = ["serde"] }
notify = "5.2.0"
serde = { version = "1.0.188", features = ["serde_derive"] }
serde_json = "1.0.107"
serde_yaml = "0.9.25"
thiserror = "1.0.49"
tokio = { version = "1.32.0", features = ["full"] }

[dev-dependencies]
pretty_assertions = "1.4.0"
15 changes: 10 additions & 5 deletions src/frontmatter_file.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
pub mod map;
pub mod keeper;

use anyhow::Result;
use camino::{Utf8Path as Path, Utf8PathBuf};
use chrono::{DateTime, Utc};
use serde::Serialize;

use crate::utf8_filepath::UTF8FilePath;
pub use map::Map;
pub use keeper::Keeper;

#[derive(Debug, Clone, Serialize)]
pub struct FrontmatterFile {
Expand Down Expand Up @@ -69,6 +69,8 @@ pub enum ReadFromPathError {
Yaml(String, serde_yaml::Error),
#[error("Failed to load: {0}")]
Io(#[from] std::io::Error),
#[error("Tried to read from path with no file name: {0}")]
NoFileNamePath(Utf8PathBuf),
}

impl FrontmatterFile {
Expand All @@ -92,8 +94,11 @@ impl FrontmatterFile {
&self.modified
}

pub fn read_from_path(path: &UTF8FilePath) -> Result<Self, ReadFromPathError> {
let name = path.name().to_owned();
pub fn read_from_path(path: &Path) -> Result<Self, ReadFromPathError> {
let name = path
.file_name()
.ok_or_else(|| ReadFromPathError::NoFileNamePath(path.to_path_buf()))?
.to_owned();
let metadata = std::fs::metadata(path)?;
let modified = metadata.modified()?.into();
let created = metadata.created()?.into();
Expand Down
Loading

0 comments on commit 17ca5a6

Please sign in to comment.