···2use nix::fcntl::{Flock, FlockArg};
34use crate::errors::{Error, Result};
05use crate::util;
6use std::fs::File;
7use std::io::{Read, Seek};
···9use std::str::FromStr;
10use std::{fs::OpenOptions, io::Write};
110012/// A unique identifier for a task. When referenced in text, it is prefixed with `tsk-`.
13pub struct Id(u32);
14···58 }
5960 pub fn next_id(&self) -> Result<Id> {
61- let mut file = util::flopen(&self.path.join("next"), FlockArg::LockExclusive)?;
62 let mut buf = String::new();
63 file.read_to_string(&mut buf)?;
64 let id = buf.trim().parse::<u32>()?;
···75 // TODO: we could improperly increment the id if the task is not written to disk/errors
76 let id = self.next_id()?;
77 let mut file = util::flopen(
78- &self.path.join("tasks").join(format!("tsk-{}.tsk", id.0)),
79 FlockArg::LockExclusive,
80 )?;
81 file.write_all(format!("{title}\n\n{body}").as_bytes())?;
···85 body,
86 file,
87 })
000000000000088 }
89}
90
···2use nix::fcntl::{Flock, FlockArg};
34use crate::errors::{Error, Result};
5+use crate::stack::TaskStack;
6use crate::util;
7use std::fs::File;
8use std::io::{Read, Seek};
···10use std::str::FromStr;
11use std::{fs::OpenOptions, io::Write};
1213+const INDEXFILE: &str = "index";
14+const TITLECACHEFILE: &str = "cache";
15/// A unique identifier for a task. When referenced in text, it is prefixed with `tsk-`.
16pub struct Id(u32);
17···61 }
6263 pub fn next_id(&self) -> Result<Id> {
64+ let mut file = util::flopen(self.path.join("next"), FlockArg::LockExclusive)?;
65 let mut buf = String::new();
66 file.read_to_string(&mut buf)?;
67 let id = buf.trim().parse::<u32>()?;
···78 // TODO: we could improperly increment the id if the task is not written to disk/errors
79 let id = self.next_id()?;
80 let mut file = util::flopen(
81+ self.path.join("tasks").join(format!("tsk-{}.tsk", id.0)),
82 FlockArg::LockExclusive,
83 )?;
84 file.write_all(format!("{title}\n\n{body}").as_bytes())?;
···88 body,
89 file,
90 })
91+ }
92+93+ fn read_stack(&self) -> Result<TaskStack> {
94+ let mut index = String::new();
95+ let mut cache = String::new();
96+ let mut index_file = util::flopen(self.path.join(INDEXFILE), FlockArg::LockExclusive)?;
97+ let mut cache_file = util::flopen(self.path.join(TITLECACHEFILE), FlockArg::LockShared)?;
98+ index_file.read_to_string(&mut index)?;
99+ for line in index.lines() {
100+101+ }
102+103+ todo!();
104 }
105}
106