diff options
Diffstat (limited to 'src/session.rs')
| -rw-r--r-- | src/session.rs | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/session.rs b/src/session.rs index 8fc6d29..a75b4c3 100644 --- a/src/session.rs +++ b/src/session.rs | |||
| @@ -1,3 +1,10 @@ | |||
| 1 | /* | ||
| 2 | * This file is part of agent686 | ||
| 3 | * Copyright (C) 2026 Salmonik <salmon@2137697.xyz> | ||
| 4 | * SPDX-License-Identifier: GPL-3.0-or-later | ||
| 5 | * https://git.2137697.xyz/agent686 | ||
| 6 | */ | ||
| 7 | |||
| 1 | use std::fs::{File, OpenOptions}; | 8 | use std::fs::{File, OpenOptions}; |
| 2 | use std::hash::{Hash, Hasher}; | 9 | use std::hash::{Hash, Hasher}; |
| 3 | use std::io::{BufRead, BufReader, Read, Write}; | 10 | use std::io::{BufRead, BufReader, Read, Write}; |
| @@ -54,9 +61,7 @@ fn restrict(path: &Path, mode: u32) { | |||
| 54 | fn lock_exclusive(file: &File, id: &str) -> Result<(), String> { | 61 | fn lock_exclusive(file: &File, id: &str) -> Result<(), String> { |
| 55 | let locked = unsafe { libc::flock(file.as_raw_fd(), libc::LOCK_EX | libc::LOCK_NB) }; | 62 | let locked = unsafe { libc::flock(file.as_raw_fd(), libc::LOCK_EX | libc::LOCK_NB) }; |
| 56 | if locked != 0 { | 63 | if locked != 0 { |
| 57 | return Err(format!( | 64 | return Err(format!("session {id} is already open in another process")); |
| 58 | "session {id} is already open in another process" | ||
| 59 | )); | ||
| 60 | } | 65 | } |
| 61 | Ok(()) | 66 | Ok(()) |
| 62 | } | 67 | } |
| @@ -258,7 +263,9 @@ impl Session { | |||
| 258 | pub fn rewrite(&mut self, system: &Value, messages: &[Value]) -> Result<(), String> { | 263 | pub fn rewrite(&mut self, system: &Value, messages: &[Value]) -> Result<(), String> { |
| 259 | use std::io::{Seek, SeekFrom, Write}; | 264 | use std::io::{Seek, SeekFrom, Write}; |
| 260 | self.file.set_len(0).map_err(|e| e.to_string())?; | 265 | self.file.set_len(0).map_err(|e| e.to_string())?; |
| 261 | self.file.seek(SeekFrom::Start(0)).map_err(|e| e.to_string())?; | 266 | self.file |
| 267 | .seek(SeekFrom::Start(0)) | ||
| 268 | .map_err(|e| e.to_string())?; | ||
| 262 | let header = json!({ | 269 | let header = json!({ |
| 263 | "t": "header", | 270 | "t": "header", |
| 264 | "session": self.id, | 271 | "session": self.id, |
