5WTKSBFRO522ILOHTH5OII4EES3DMLWMTA47PXCVWCIGMXIS77KAC
LSRFYRWWQXJ2LVGZ7FWF5O57E4RK45EE6NWLNTRSRO5M7TFW7PZAC
B2BZZXWMRR2FYPBMSSQ6WBCOWX5R3JOXSESX4LFUAQF3FOS4APBQC
TXF4WACU3YJSUMTXJ2VZ3K7OXL2Z564R5KGMVMAFIVXPCLYCMD2AC
F6L2P7VTKQUV64O66XPEIRG46ZO36E4FWFN3KNMBPRHQLQWL6HSAC
B2MSSEJB4GIBFA6F2HRMK7FXUHJBZIZFK6NOHY7YZUSHRB53URGQC
T2HK3ZSDLLLGHROM77MND4UZF663WSHT5J2CT7ZMXDH6MMIZFOAQC
VEN5WJYRT23IT77JAAZ5CJRSW3GUTTNMAECT3WVTHQA34HI4646AC
K7M77GF5ILC4KKKYPTLZRZ2OND7DOQDQNRYKM3N6XV2DMJURYA3QC
EEBZMKMLEADO3ODXOQ7VNZNT36L7BYFRQUS2S2HLDVBZI7FHZQFQC
name = "fallible-iterator"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4443176a9f2c162692bd3d352d745ef9413eec5782a80d8fd6f8a1ac692a07f7"
[[package]]
name = "fallible-streaming-iterator"
version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7360491ce676a36bf9bb3c56c1aa791658183a54d2744120f27285738d90465a"
[[package]]
name = "libsqlite3-sys"
version = "0.20.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e3a245984b1b06c291f46e27ebda9f369a94a1ab8461d0e845e23f9ced01f5db"
dependencies = [
"pkg-config",
"vcpkg",
]
[[package]]
name = "linked-hash-map"
version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8dd5a6d5999d9907cda8ed67bbd137d3af8085216c2ac62de5be860bd41f304a"
[[package]]
]
[[package]]
name = "rusqlite"
version = "0.24.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4c78c3275d9d6eb684d2db4b2388546b32fdae0586c20a82f3905d21ea78b9ef"
dependencies = [
"bitflags",
"fallible-iterator",
"fallible-streaming-iterator",
"libsqlite3-sys",
"lru-cache",
"memchr",
"smallvec",
Ok(())
}
"import" => {
let path = std::env::args().into_iter().nth(2).unwrap_or_default();
dbg!(&path);
let db = rusqlite::Connection::open(&path)?;
let mut stmt = db.prepare(
"select * from history left join places on places.id=history.place_id left join \
commands on history.command_id=commands.id",
)?;
#[derive(Debug, Ord, PartialOrd, Eq, PartialEq)]
struct DBEntry {
session: i64,
start_time: i64,
duration: Option<i64>,
exit_status: Option<i64>,
hostname: String,
pwd: String,
command: String,
}
let entries = stmt
.query_map(params![], |row| {
Ok(DBEntry {
session: row.get(1)?,
exit_status: row.get(4)?,
start_time: row.get(5)?,
duration: row.get(6)?,
hostname: row.get(8)?,
pwd: row.get(9)?,
command: row.get(11)?,
})
})?
.collect::<Result<BTreeSet<_>, _>>()?;
println!("{:?}", entries.len());
let mut session_ids: HashMap<(i64, String), Uuid> = HashMap::new();
let store = crate::store::new();
let xdg_dirs = xdg::BaseDirectories::with_prefix("histdb-rs").unwrap();
let datadir_path = xdg_dirs.get_data_home();
for entry in entries {
if entry.duration.is_none()
|| entry.exit_status.is_none()
|| entry.command.trim().is_empty()
{
continue;
}
let session_id = session_ids
.entry((entry.session, entry.hostname.clone()))
.or_insert(Uuid::new_v4());
let start_time = entry.start_time;
let time_start = chrono::DateTime::<Utc>::from_utc(
chrono::NaiveDateTime::from_timestamp(start_time, 0),
Utc,
);
let time_finished = chrono::DateTime::<Utc>::from_utc(
chrono::NaiveDateTime::from_timestamp(start_time + entry.duration.unwrap(), 0),
Utc,
);
let hostname = entry.hostname;
let pwd = PathBuf::from(entry.pwd);
let result = entry.exit_status.unwrap().try_into().unwrap();
let user = String::new();
let command = entry.command;
let entry = crate::entry::Entry {
time_finished,
time_start,
hostname,
pwd,
result,
session_id: *session_id,
user,
command,
};
store.add_entry(&entry, &datadir_path).unwrap();
}
let hostname = hostname::get()?.to_string_lossy().to_string();
store.commit(&hostname)?;
pub fn add(&self, entry: Entry) -> Result<(), Error> {
if entry.command.is_empty() {
return Ok(());
}
let xdg_dirs = xdg::BaseDirectories::with_prefix("histdb-rs").unwrap();
let datadir_path = xdg_dirs.get_data_home();
pub fn add_entry(&self, entry: &Entry, datadir_path: impl AsRef<Path>) -> Result<(), Error> {
self.commit(hostname)?;
Ok(())
}
pub fn add(&self, entry: Entry) -> Result<(), Error> {
if entry.command.is_empty() {
return Ok(());
}
let xdg_dirs = xdg::BaseDirectories::with_prefix("histdb-rs").unwrap();
let datadir_path = xdg_dirs.get_data_home();
self.add_entry(&entry, datadir_path)?;
self.commit(format!("add entry from {:?}", &entry.hostname))?;