File tree Expand file tree Collapse file tree 2 files changed +32
-8
lines changed
Expand file tree Collapse file tree 2 files changed +32
-8
lines changed Original file line number Diff line number Diff line change @@ -40,13 +40,8 @@ pub fn main() -> anyhow::Result<()> {
4040
4141 log:: info!( "starting watt daemon" ) ;
4242
43- let lock_path = PathBuf :: from ( "/run/watt.lock" ) ;
44- let _lock = lock:: LockFile :: acquire ( & lock_path) . with_context ( || {
45- format ! (
46- "failed to acquire exclusive lock at {}" ,
47- lock_path. display( )
48- )
49- } ) ?;
43+ let lock_path = PathBuf :: from ( "/run/watt/lock" ) ;
44+ let _lock = lock:: LockFile :: acquire ( & lock_path) ?;
5045
5146 system:: run_daemon ( config)
5247}
Original file line number Diff line number Diff line change @@ -2,11 +2,15 @@ use std::{
22 error:: Error ,
33 fmt,
44 fs:: {
5+ self ,
56 File ,
67 OpenOptions ,
78 } ,
89 ops,
9- os:: unix:: fs:: OpenOptionsExt ,
10+ os:: unix:: fs:: {
11+ DirBuilderExt ,
12+ OpenOptionsExt ,
13+ } ,
1014 path:: {
1115 Path ,
1216 PathBuf ,
@@ -64,6 +68,31 @@ impl LockFile {
6468 }
6569
6670 pub fn acquire ( lock_path : & Path ) -> Result < Self , LockFileError > {
71+ // Ensure parent directory exists with proper permissions
72+ if let Some ( parent) = lock_path. parent ( ) {
73+ if !parent. exists ( ) {
74+ fs:: DirBuilder :: new ( )
75+ . mode ( 0o755 )
76+ . recursive ( true )
77+ . create ( parent)
78+ . map_err ( |error| {
79+ log:: error!(
80+ "failed to create lock directory {}: {}" ,
81+ parent. display( ) ,
82+ error
83+ ) ;
84+ LockFileError {
85+ path : lock_path. to_owned ( ) ,
86+ message : Some ( format ! (
87+ "cannot create directory {}: {}" ,
88+ parent. display( ) ,
89+ error
90+ ) ) ,
91+ }
92+ } ) ?;
93+ }
94+ }
95+
6796 #[ allow( clippy:: suspicious_open_options) ]
6897 let file = OpenOptions :: new ( )
6998 . create ( true )
You can’t perform that action at this time.
0 commit comments