tangled
alpha
login
or
join now
ngp.computer
/
tsk
A file-based task manager
0
fork
atom
overview
issues
pulls
pipelines
Basic task creation done
ngp.computer
1 year ago
e1404430
2c7d894a
+6
-9
1 changed file
expand all
collapse all
unified
split
src
workspace.rs
+6
-9
src/workspace.rs
···
3
3
4
4
use crate::errors::{Error, Result};
5
5
use std::fs::File;
6
6
-
use std::io::{BufReader, Seek};
6
6
+
use std::io::{Read, Seek};
7
7
use std::path::PathBuf;
8
8
-
use std::{
9
9
-
fs::OpenOptions,
10
10
-
io::{BufRead, Write},
11
11
-
};
8
8
+
use std::{fs::OpenOptions, io::Write};
12
9
13
10
pub struct Id(u32);
14
11
···
43
40
if !tsk_dir.exists() {
44
41
return Err(Error::Uninitialized);
45
42
} else {
46
46
-
Ok(Self { path })
43
43
+
Ok(Self { path: tsk_dir })
47
44
}
48
45
}
49
46
···
51
48
let file = OpenOptions::new()
52
49
.read(true)
53
50
.write(true)
54
54
-
.create(true)
51
51
+
.create(false)
55
52
.open(self.path.join("next"))?;
56
53
let mut lock =
57
54
Flock::lock(file, FlockArg::LockExclusive).map_err(|(_, errno)| Error::Lock(errno))?;
58
55
let mut buf = String::new();
59
59
-
BufReader::new(&*lock).read_line(&mut buf)?;
56
56
+
lock.read_to_string(&mut buf)?;
60
57
let id = buf.trim().parse::<u32>()?;
61
58
// reset the files contents
62
59
lock.set_len(0)?;
···
74
71
.read(true)
75
72
.write(true)
76
73
.create(true)
77
77
-
.open(self.path.join(format!("tsk-{}.tsk", id.0)))?;
74
74
+
.open(self.path.join("tasks").join(format!("tsk-{}.tsk", id.0)))?;
78
75
let mut file =
79
76
Flock::lock(file, FlockArg::LockExclusive).map_err(|(_, errno)| Error::Lock(errno))?;
80
77
file.write_all(format!("{title}\n\n{body}").as_bytes())?;