forked from NG-SD-Plugins/PowerTools
Fix symlink creation again... fix reading file creation->access time
This commit is contained in:
parent
6f2c2b186f
commit
be60be71ac
4 changed files with 30 additions and 17 deletions
|
@ -62,9 +62,10 @@ fn get_some_settings_by_app_id(steam_app_id: u32, cli: &'static Cli) -> std::io:
|
|||
.filter_map(|res| res.ok())
|
||||
.filter(|f| f.path().extension().map(|ext| ext == file_util::RON_EXTENSION).unwrap_or(false))
|
||||
.filter_map(|f| f.metadata().ok().map(|meta| (f, meta)))
|
||||
.filter_map(|(f, meta)| meta.created().ok().map(|time| (f, meta, time)))
|
||||
.filter_map(|(f, meta)| meta.modified().ok().map(|time| (f, meta, time)))
|
||||
.collect();
|
||||
files.sort_by(|(_, _, a_created), (_, _, b_created)| a_created.cmp(b_created));
|
||||
let files_len = files.len();
|
||||
|
||||
let mut results = Vec::with_capacity(MAX_RESULTS);
|
||||
for (_, (f, _, _)) in files.into_iter().enumerate().take_while(|(i, _)| *i < MAX_RESULTS) {
|
||||
|
@ -72,12 +73,14 @@ fn get_some_settings_by_app_id(steam_app_id: u32, cli: &'static Cli) -> std::io:
|
|||
let setting = match ron::de::from_reader(reader) {
|
||||
Ok(x) => x,
|
||||
Err(e) => {
|
||||
log::debug!("Error while reading {}: {}", f.path().display(), e);
|
||||
let e_msg = format!("{}", e);
|
||||
return Err(std::io::Error::new(std::io::ErrorKind::InvalidData, e_msg));
|
||||
}
|
||||
};
|
||||
results.push(setting);
|
||||
}
|
||||
log::debug!("Got {} results (from {} files) for {}", results.len(), files_len, app_id_folder.display());
|
||||
Ok(results)
|
||||
}
|
||||
|
||||
|
@ -89,7 +92,7 @@ pub async fn get_setting_by_app_id_handler(
|
|||
) -> std::io::Result<impl Responder> {
|
||||
let id: u32 = *id;
|
||||
#[cfg(debug_assertions)]
|
||||
println!("Accept: {}", accept.to_string());
|
||||
log::debug!("Accept: {}", accept.to_string());
|
||||
let preferred = accept.preference();
|
||||
if super::is_mime_type_ron_capable(&preferred) {
|
||||
// Send RON
|
||||
|
|
|
@ -62,24 +62,29 @@ pub async fn save_setting_handler(
|
|||
}
|
||||
}
|
||||
|
||||
log::debug!("Saved to {}, building symlinks", path_ron.display());
|
||||
|
||||
// create symlinks for other ways of looking up these settings files
|
||||
let filename_ron = file_util::filename(next_id, file_util::RON_EXTENSION);
|
||||
let filename_json = file_util::filename(next_id, file_util::JSON_EXTENSION);
|
||||
|
||||
// create symlinks to app id folder
|
||||
let app_id_folder = file_util::setting_folder_by_app_id(&cli.folder, parsed_data.steam_app_id);
|
||||
log::debug!("App id folder {}", app_id_folder.display());
|
||||
if !app_id_folder.exists() {
|
||||
std::fs::create_dir(&app_id_folder)?;
|
||||
}
|
||||
#[cfg(target_family = "windows")] // NOTE: windows support is untested and unmaintained
|
||||
{
|
||||
std::os::windows::fs::symlink_file(&path_ron, app_id_folder.join(&filename_ron).canonicalize()?)?;
|
||||
std::os::windows::fs::symlink_file(&path_json, app_id_folder.join(&filename_json).canonicalize()?)?;
|
||||
log::debug!("Symlinking {} -> {}", app_id_folder.join(&filename_ron).display(), path_ron.canonicalize()?.display());
|
||||
std::os::windows::fs::symlink_file(&path_ron.canonicalize()?, app_id_folder.join(&filename_ron))?;
|
||||
std::os::windows::fs::symlink_file(&path_json.canonicalize()?, app_id_folder.join(&filename_json))?;
|
||||
}
|
||||
#[cfg(target_family = "unix")]
|
||||
{
|
||||
std::os::unix::fs::symlink(&path_ron, app_id_folder.join(&filename_ron).canonicalize()?)?;
|
||||
std::os::unix::fs::symlink(&path_json, app_id_folder.join(&filename_json).canonicalize()?)?;
|
||||
log::debug!("Symlinking {} -> {}", app_id_folder.join(&filename_ron).display(), path_ron.canonicalize()?.display());
|
||||
std::os::unix::fs::symlink(&path_ron.canonicalize()?, app_id_folder.join(&filename_ron))?;
|
||||
std::os::unix::fs::symlink(&path_json.canonicalize()?, app_id_folder.join(&filename_json))?;
|
||||
}
|
||||
|
||||
// create symlinks for user id folder
|
||||
|
@ -89,13 +94,15 @@ pub async fn save_setting_handler(
|
|||
}
|
||||
#[cfg(target_family = "windows")] // NOTE: windows support is untested and unmaintained
|
||||
{
|
||||
std::os::windows::fs::symlink_file(&path_ron, user_id_folder.join(&filename_ron).canonicalize()?)?;
|
||||
std::os::windows::fs::symlink_file(&path_json, user_id_folder.join(&filename_json).canonicalize()?)?;
|
||||
log::debug!("Symlinking {} -> {}", user_id_folder.join(&filename_ron).display(), path_ron.canonicalize()?.display());
|
||||
std::os::windows::fs::symlink_file(&path_ron.canonicalize()?, user_id_folder.join(&filename_ron))?;
|
||||
std::os::windows::fs::symlink_file(&path_json.canonicalize()?, user_id_folder.join(&filename_json))?;
|
||||
}
|
||||
#[cfg(target_family = "unix")]
|
||||
{
|
||||
std::os::unix::fs::symlink(&path_ron, user_id_folder.join(&filename_ron).canonicalize()?)?;
|
||||
std::os::unix::fs::symlink(&path_json, user_id_folder.join(&filename_json).canonicalize()?)?;
|
||||
log::debug!("Symlinking {} -> {}", user_id_folder.join(&filename_ron).display(), path_ron.canonicalize()?.display());
|
||||
std::os::unix::fs::symlink(&path_ron.canonicalize()?, user_id_folder.join(&filename_ron))?;
|
||||
std::os::unix::fs::symlink(&path_json.canonicalize()?, user_id_folder.join(&filename_json))?;
|
||||
}
|
||||
|
||||
// create symlinks for each tag
|
||||
|
@ -106,13 +113,15 @@ pub async fn save_setting_handler(
|
|||
}
|
||||
#[cfg(target_family = "windows")] // NOTE: windows support is untested and unmaintained
|
||||
{
|
||||
std::os::windows::fs::symlink_file(&path_ron, tag_folder.join(&filename_ron).canonicalize()?)?;
|
||||
std::os::windows::fs::symlink_file(&path_json, tag_folder.join(&filename_json).canonicalize()?)?;
|
||||
log::debug!("Symlinking {} -> {}", tag_folder.join(&filename_ron).display(), path_ron.canonicalize()?.display());
|
||||
std::os::windows::fs::symlink_file(&path_ron.canonicalize()?, tag_folder.join(&filename_ron))?;
|
||||
std::os::windows::fs::symlink_file(&path_json.canonicalize()?, tag_folder.join(&filename_json))?;
|
||||
}
|
||||
#[cfg(target_family = "unix")]
|
||||
{
|
||||
std::os::unix::fs::symlink(&path_ron, tag_folder.join(&filename_ron).canonicalize()?)?;
|
||||
std::os::unix::fs::symlink(&path_json, tag_folder.join(&filename_json).canonicalize()?)?;
|
||||
log::debug!("Symlinking {} -> {}", tag_folder.join(&filename_ron).display(), path_ron.canonicalize()?.display());
|
||||
std::os::unix::fs::symlink(&path_ron.canonicalize()?, tag_folder.join(&filename_ron))?;
|
||||
std::os::unix::fs::symlink(&path_json.canonicalize()?, tag_folder.join(&filename_json))?;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ pub struct Cli {
|
|||
pub log: std::path::PathBuf,
|
||||
|
||||
/// Perform maintenance tasks
|
||||
#[arg(short, long)]
|
||||
#[arg(long)]
|
||||
pub fix: bool,
|
||||
}
|
||||
|
||||
|
|
|
@ -138,13 +138,14 @@ pub fn next_setting_id(root: impl AsRef<Path>) -> u128 {
|
|||
let mut last_id = *lock;
|
||||
if last_id == 0 {
|
||||
// needs init
|
||||
last_id = 1;
|
||||
let mut path = setting_path_by_id(root.as_ref(), last_id, RON_EXTENSION);
|
||||
while path.exists() {
|
||||
last_id += 1;
|
||||
path = setting_path_by_id(root.as_ref(), last_id, RON_EXTENSION);
|
||||
}
|
||||
*lock = last_id;
|
||||
println!("setting id initialized to {}", last_id);
|
||||
*lock = last_id - 1;
|
||||
log::info!("setting id initialized to {}", last_id);
|
||||
}
|
||||
*lock += 1;
|
||||
*lock
|
||||
|
|
Loading…
Reference in a new issue