11/// Module for directory management
22use log:: { debug, info, warn} ;
33
4- use crate :: util:: ResultAccumulator ;
54use crate :: config:: MgmtConfig ;
65use crate :: prelude:: AppResult ;
76use crate :: ssh:: { self , SshConnection , SshCredentials } ;
7+ use crate :: util:: ResultAccumulator ;
88use crate :: { Group , NewEntity } ;
99
1010pub fn add_user_directories < T > (
2424 Ok ( ( ) )
2525}
2626
27- pub fn delete_user_directories < T > (
28- username : & str ,
29- config : & MgmtConfig ,
30- credentials : & T ,
31- ) -> AppResult
27+ pub fn delete_user_directories < T > ( username : & str , config : & MgmtConfig , credentials : & T ) -> AppResult
3228where
3329 T : SshCredentials ,
3430{
@@ -59,10 +55,16 @@ where
5955 warn ! ( "No root directory on compute nodes provided in config. Unable to delete user directories on nodes." ) ;
6056 return Ok ( ( ) ) ;
6157 }
62-
58+
6359 let mut rm_exit_codes = Vec :: new ( ) ;
6460 for server in config. compute_nodes . iter ( ) {
65- info ! ( "{}" , format!( "Connecting to compute node {} for directory deletion" , server) ) ;
61+ info ! (
62+ "{}" ,
63+ format!(
64+ "Connecting to compute node {} for directory deletion" ,
65+ server
66+ )
67+ ) ;
6668 let sess = SshConnection :: new ( server, config, credentials. clone ( ) ) ;
6769 // Delete directory
6870 let directory = format ! ( "{}/{}" , config. compute_node_root_dir, username) ;
@@ -79,17 +81,20 @@ where
7981 all_exit_codes_are_zero,
8082 "Not all compute nodes returned exit code 0 during directory deletion!" . to_owned ( ) ,
8183 ) ;
82-
84+
8385 if !errors_from_codes. errs . is_empty ( ) {
84- warn ! ( "{}: {}" , errors_from_codes. base_err_msg, errors_from_codes. errs. join( "\n " ) ) ;
86+ warn ! (
87+ "{}: {}" ,
88+ errors_from_codes. base_err_msg,
89+ errors_from_codes. errs. join( "\n " )
90+ ) ;
8591 } else {
8692 info ! ( "Successfully deleted directories on compute nodes." ) ;
8793 }
88-
94+
8995 Ok ( ( ) )
9096}
9197
92-
9398/// Establish SSH connection to NFS hosts and delete user directory
9499fn delete_nfs_dir < T > ( username : & str , config : & MgmtConfig , credentials : & T ) -> AppResult
95100where
@@ -112,15 +117,23 @@ where
112117 let current_nfs_host = & config. nfs_host [ i] ;
113118 let current_nfs_root_dir = & config. nfs_root_dir [ i] ;
114119
115- info ! ( "Connecting to NFS host {} for directory deletion" , current_nfs_host) ;
120+ info ! (
121+ "Connecting to NFS host {} for directory deletion" ,
122+ current_nfs_host
123+ ) ;
116124 let sess = SshConnection :: new ( current_nfs_host, config, credentials. clone ( ) ) ;
117125
118126 // Infer user group
119127 let mut group_dir = "staff" ;
120- if username. chars ( ) . last ( ) . map ( |c| c. is_ascii_digit ( ) ) . unwrap_or ( false ) {
128+ if username
129+ . chars ( )
130+ . last ( )
131+ . map ( |c| c. is_ascii_digit ( ) )
132+ . unwrap_or ( false )
133+ {
121134 group_dir = "students" ;
122135 }
123-
136+
124137 let directory = format ! ( "{}/{}/{}" , current_nfs_root_dir, group_dir, username) ;
125138 let ( dir_exit_code, _) = delete_directory ( & sess, & directory) ?;
126139
@@ -131,17 +144,21 @@ where
131144 ) ) ;
132145 } else {
133146 info ! (
134- "{}" ,
135- format!(
136- "Successfully deleted user directory on NFS host {}." ,
137- current_nfs_host
138- )
139- ) ;
147+ "{}" ,
148+ format!(
149+ "Successfully deleted user directory on NFS host {}." ,
150+ current_nfs_host
151+ )
152+ ) ;
140153 }
141154 }
142155
143156 if !detected_errors. errs . is_empty ( ) {
144- warn ! ( "{}: {}" , detected_errors. base_err_msg, detected_errors. errs. join( "\n " ) ) ;
157+ warn ! (
158+ "{}: {}" ,
159+ detected_errors. base_err_msg,
160+ detected_errors. errs. join( "\n " )
161+ ) ;
145162 }
146163
147164 Ok ( ( ) )
@@ -158,10 +175,13 @@ where
158175 warn ! ( "No home host provided in config. Unable to delete user home directory." ) ;
159176 return Ok ( ( ) ) ;
160177 }
161-
178+
162179 info ! (
163180 "{}" ,
164- format!( "Connecting to home host {} for directory deletion" , & config. home_host)
181+ format!(
182+ "Connecting to home host {} for directory deletion" ,
183+ & config. home_host
184+ )
165185 ) ;
166186 let sess = SshConnection :: new ( & config. home_host , config, credentials. clone ( ) ) ;
167187
@@ -171,16 +191,16 @@ where
171191
172192 if dir_exit_code == 0 {
173193 info ! ( "Successfully deleted user home directory." ) ;
174-
175194 } else {
176- warn ! ( "{}" , format!( "Failed to delete user home directory: {}" , & directory) ) ;
195+ warn ! (
196+ "{}" ,
197+ format!( "Failed to delete user home directory: {}" , & directory)
198+ ) ;
177199 }
178-
200+
179201 Ok ( ( ) )
180202}
181203
182-
183-
184204/// Establish SSH connection to each compute node, make user directory and set quota
185205fn handle_compute_nodes < T > ( entity : & NewEntity , config : & MgmtConfig , credentials : & T ) -> AppResult
186206where
0 commit comments