1
1
use std:: io:: { Read , SeekFrom } ;
2
2
3
3
use crate :: {
4
- prelude:: Credentials ,
4
+ prelude:: { Credentials , DirectoryInfo } ,
5
5
util:: io:: { self , IOError } ,
6
6
{ state:: ProfilePathId , State } ,
7
7
} ;
@@ -74,7 +74,6 @@ pub async fn get_logs(
74
74
profile_path : ProfilePathId ,
75
75
clear_contents : Option < bool > ,
76
76
) -> crate :: Result < Vec < Logs > > {
77
- let state = State :: get ( ) . await ?;
78
77
let profile_path =
79
78
if let Some ( p) = crate :: profile:: get ( & profile_path, None ) . await ? {
80
79
p. profile_id ( )
@@ -85,7 +84,7 @@ pub async fn get_logs(
85
84
. into ( ) ) ;
86
85
} ;
87
86
88
- let logs_folder = state . directories . profile_logs_dir ( & profile_path) . await ?;
87
+ let logs_folder = DirectoryInfo :: profile_logs_dir ( & profile_path) . await ?;
89
88
let mut logs = Vec :: new ( ) ;
90
89
if logs_folder. exists ( ) {
91
90
for entry in std:: fs:: read_dir ( & logs_folder)
@@ -138,8 +137,7 @@ pub async fn get_output_by_filename(
138
137
file_name : & str ,
139
138
) -> crate :: Result < CensoredString > {
140
139
let state = State :: get ( ) . await ?;
141
- let logs_folder =
142
- state. directories . profile_logs_dir ( profile_subpath) . await ?;
140
+ let logs_folder = DirectoryInfo :: profile_logs_dir ( profile_subpath) . await ?;
143
141
let path = logs_folder. join ( file_name) ;
144
142
145
143
let credentials: Vec < Credentials > =
@@ -201,8 +199,7 @@ pub async fn delete_logs(profile_path: ProfilePathId) -> crate::Result<()> {
201
199
. into ( ) ) ;
202
200
} ;
203
201
204
- let state = State :: get ( ) . await ?;
205
- let logs_folder = state. directories . profile_logs_dir ( & profile_path) . await ?;
202
+ let logs_folder = DirectoryInfo :: profile_logs_dir ( & profile_path) . await ?;
206
203
for entry in std:: fs:: read_dir ( & logs_folder)
207
204
. map_err ( |e| IOError :: with_path ( e, & logs_folder) ) ?
208
205
{
@@ -230,8 +227,7 @@ pub async fn delete_logs_by_filename(
230
227
. into ( ) ) ;
231
228
} ;
232
229
233
- let state = State :: get ( ) . await ?;
234
- let logs_folder = state. directories . profile_logs_dir ( & profile_path) . await ?;
230
+ let logs_folder = DirectoryInfo :: profile_logs_dir ( & profile_path) . await ?;
235
231
let path = logs_folder. join ( filename) ;
236
232
io:: remove_dir_all ( & path) . await ?;
237
233
Ok ( ( ) )
@@ -240,6 +236,23 @@ pub async fn delete_logs_by_filename(
240
236
#[ tracing:: instrument]
241
237
pub async fn get_latest_log_cursor (
242
238
profile_path : ProfilePathId ,
239
+ cursor : u64 , // 0 to start at beginning of file
240
+ ) -> crate :: Result < LatestLogCursor > {
241
+ get_generic_live_log_cursor ( profile_path, "latest.log" , cursor) . await
242
+ }
243
+
244
+ #[ tracing:: instrument]
245
+ pub async fn get_std_log_cursor (
246
+ profile_path : ProfilePathId ,
247
+ cursor : u64 , // 0 to start at beginning of file
248
+ ) -> crate :: Result < LatestLogCursor > {
249
+ get_generic_live_log_cursor ( profile_path, "latest_stdout.log" , cursor) . await
250
+ }
251
+
252
+ #[ tracing:: instrument]
253
+ pub async fn get_generic_live_log_cursor (
254
+ profile_path : ProfilePathId ,
255
+ log_file_name : & str ,
243
256
mut cursor : u64 , // 0 to start at beginning of file
244
257
) -> crate :: Result < LatestLogCursor > {
245
258
let profile_path =
@@ -253,8 +266,8 @@ pub async fn get_latest_log_cursor(
253
266
} ;
254
267
255
268
let state = State :: get ( ) . await ?;
256
- let logs_folder = state . directories . profile_logs_dir ( & profile_path) . await ?;
257
- let path = logs_folder. join ( "latest.log" ) ;
269
+ let logs_folder = DirectoryInfo :: profile_logs_dir ( & profile_path) . await ?;
270
+ let path = logs_folder. join ( log_file_name ) ;
258
271
if !path. exists ( ) {
259
272
// Allow silent failure if latest.log doesn't exist (as the instance may have been launched, but not yet created the file)
260
273
return Ok ( LatestLogCursor {
0 commit comments