fix(core): fix bug that caused multiple processes to overwrite logs
This commit is contained in:
parent
befcbd984e
commit
6eb3fdfcf3
|
@ -51,8 +51,8 @@ impl Default for CliModule {
|
|||
#[derive(Debug, PartialEq)]
|
||||
pub enum LogMode {
|
||||
Read,
|
||||
Write,
|
||||
Append,
|
||||
AppendOnly,
|
||||
CleanAndAppend,
|
||||
}
|
||||
|
||||
pub struct CliModuleArgs {
|
||||
|
|
|
@ -46,13 +46,19 @@ impl FileProxy {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn set_output_file(&self, path: &Path, truncate: bool, append: bool) -> Result<()> {
|
||||
pub fn set_output_file(&self, path: &Path, read_only: bool, create_new: bool) -> Result<()> {
|
||||
// Remove previous log, if present
|
||||
if create_new && !read_only {
|
||||
if path.is_file() {
|
||||
std::fs::remove_file(path)?;
|
||||
}
|
||||
}
|
||||
|
||||
let mut log_file = OpenOptions::new()
|
||||
.read(true)
|
||||
.write(true)
|
||||
.write(!read_only)
|
||||
.create(true)
|
||||
.truncate(truncate)
|
||||
.append(append)
|
||||
.append(true)
|
||||
.open(path)?;
|
||||
let mut lock = self.output.lock().expect("unable to obtain FileProxy lock");
|
||||
|
||||
|
|
|
@ -17,6 +17,9 @@
|
|||
* along with espanso. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
// This is needed to avoid showing a console window when starting espanso on Windows
|
||||
// TODO #![windows_subsystem = "windows"]
|
||||
|
||||
#[macro_use]
|
||||
extern crate lazy_static;
|
||||
|
||||
|
@ -309,8 +312,8 @@ fn main() {
|
|||
log_proxy
|
||||
.set_output_file(
|
||||
&paths.runtime.join(LOG_FILE_NAME),
|
||||
handler.log_mode == LogMode::Write,
|
||||
handler.log_mode == LogMode::Append,
|
||||
handler.log_mode == LogMode::Read,
|
||||
handler.log_mode == LogMode::CleanAndAppend,
|
||||
)
|
||||
.expect("unable to set up log output file");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user