Diff
Not logged in

Differences From Artifact [201f598b88]:

To Artifact [6d6dfb87b8]:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
..
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
..
54
55
56
57
58
59
60

61
62
63
64
65
66
67
68
69
70
71
72




73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
..
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
...
114
115
116
117
118
119
120

121
122
123
124
125
126
127
128
129
...
133
134
135
136
137
138
139
140


141
142
143
144
145
146
147
...
160
161
162
163
164
165
166

167
168
169
170
171
172
173
174
175
176
177
178
179
...
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199

200
201
202
203
204
205
206
207
...
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
...
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243

244
245
246
247
248
249
250
251
252

253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298


299
300
301
302
303
304
305
306
307
308
309
310

311

312
313
314
315
316
317
318
319
320
321
322
...
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345

346
347
348
349
350
351
352
353
354
355
356
357
358
359
360

361
362
363
364
365
366

367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
// Copyright 2015 MaidSafe.net limited.
//
// This SAFE Network Software is licensed to you under (1) the MaidSafe.net Commercial License,
// version 1.0 or later, or (2) The General Public License (GPL), version 3, depending on which
// licence you accepted on initial access to the Software (the "Licences").
//
// By contributing code to the SAFE Network Software, or to this project generally, you agree to be
// bound by the terms of the MaidSafe Contributor Agreement, version 1.0.  This, along with the
// Licenses can be found in the root directory of this project at LICENSE, COPYING and CONTRIBUTOR.
//
// Unless required by applicable law or agreed to in writing, the SAFE Network Software distributed
// under the GPL Licence is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied.
//
// Please review the Licences for the specific language governing permissions and limitations
// relating to use of the SAFE Network Software.
................................................................................
        unknown_lints, unsafe_code, unused, unused_allocation, unused_attributes,
        unused_comparisons, unused_features, unused_parens, while_true)]
#![warn(trivial_casts, trivial_numeric_casts, unused_extern_crates, unused_import_braces,
        unused_qualifications, unused_results)]
#![allow(box_pointers, fat_ptr_transmutes, missing_copy_implementations,
         missing_debug_implementations, variant_size_differences)]

#![cfg_attr(feature="clippy", feature(plugin))]
#![cfg_attr(feature="clippy", plugin(clippy))]
#![cfg_attr(feature="clippy", deny(clippy))]
#![cfg_attr(feature="clippy", allow(use_debug, print_stdout))]

#![allow(unused_extern_crates)]#[macro_use]
extern crate maidsafe_utilities;
extern crate time;
extern crate routing;
extern crate safe_core;
#[macro_use]
extern crate unwrap;


use routing::XOR_NAME_LEN;
................................................................................
use safe_core::nfs::helper::file_helper::FileHelper;
use safe_core::nfs::helper::writer::Mode;
use std::sync::{Arc, Mutex};

fn create_account() -> Result<Client, NfsError> {
    let mut secret_0 = String::new();
    let mut secret_1 = String::new();


    println!("\n\tAccount Creation");
    println!("\t================");

    println!("\n------------ Enter account-locator ---------------");
    let _ = std::io::stdin().read_line(&mut secret_0);
    secret_0 = secret_0.trim().to_string();

    println!("\n------------ Enter password ---------------");
    let _ = std::io::stdin().read_line(&mut secret_1);
    secret_1 = secret_1.trim().to_string();





    // Account Creation
    println!("\nTrying to create an account ...");
    let _ = unwrap!(Client::create_account(&secret_0, &secret_1));
    println!("Account Created Successfully !!");
    println!("\n\n\tAuto Account Login");
    println!("\t==================");

    // Log into the created account
    println!("\nTrying to log into the created account using supplied credentials ...");
    let client = try!(Client::log_in(&secret_0, &secret_1));
    println!("Account Login Successful !!");
    Ok(client)
}

fn get_root_directory(client: Arc<Mutex<Client>>) -> Result<DirectoryListing, NfsError> {
    let directory_helper = DirectoryHelper::new(client.clone());
    directory_helper.get_user_root_directory_listing()
................................................................................
        println!("{} can not be empty", placeholder);
        println!("------Enter Directory name--------");
        let _ = std::io::stdin().read_line(&mut txt);
    }
    txt
}

#[cfg_attr(feature="clippy", allow(indexing_slicing))]
fn format_version_id(version_id: &[u8; XOR_NAME_LEN]) -> String {
    let mut version = String::new();
    for byte in &version_id[0..4] {
        version.push_str(&byte.to_string()[..]);
    }
    version.push_str("..");
    for byte in &version_id[(XOR_NAME_LEN - 4)..XOR_NAME_LEN] {
................................................................................
    version
}

fn get_child_directory(client: Arc<Mutex<Client>>,
                       directory: &mut DirectoryListing)
                       -> Result<DirectoryListing, NfsError> {
    let directory_name = &get_user_string("Directory name");

    let directory_metadata = try!(directory.find_sub_directory(directory_name)
        .ok_or(NfsError::DirectoryNotFound));
    let directory_helper = DirectoryHelper::new(client);

    directory_helper.get(directory_metadata.get_key())
}

fn directory_operation(option: u32,
                       client: Arc<Mutex<Client>>,
................................................................................
        1 => {
            // Create directory
            println!("----------Select the Directory type-----------");
            println!("1. Versioned Private Directory");
            println!("2. Versioned Public Directory");
            println!("3. UnVersioned Private Directory");
            println!("4. UnVersioned Public Directory");
            match get_user_string("number corresponding to the type").trim().parse::<usize>() {


                Ok(index) => {
                    if index > 4 {
                        println!("Invalid input");
                        return Ok(());
                    }
                    let name = get_user_string("Directory name");
                    let versioned = match index {
................................................................................
                    let tag_type = if versioned {
                        nfs::VERSIONED_DIRECTORY_LISTING_TAG
                    } else {
                        nfs::UNVERSIONED_DIRECTORY_LISTING_TAG
                    };

                    let directory_helper = DirectoryHelper::new(client.clone());

                    let _ = try!(directory_helper.create(name.clone(),
                                                         tag_type,
                                                         vec![],
                                                         versioned,
                                                         access_level,
                                                         Some(&mut directory)));
                    println!("Created Directory - {}", name);
                }
                Err(_) => println!("Invalid input"),
            };
        }
        2 => {
            // List directories
................................................................................
            let directory_metadata = directory.get_sub_directories();
            if directory_metadata.is_empty() {
                println!("No directories found");
            } else {
                println!("List of directories");
                println!("\t        Created On                  Name ");
                println!("\t =========================       ==========");
                for metatata in directory_metadata {
                    println!("\t {:?} \t {}",
                             unwrap!(time::strftime("%d-%m-%Y %H:%M UTC",
                                                    &metatata.get_created_time())),
                             metatata.get_name());
                }
            }
        }
        3 => {
            // List versions
            let child = try!(get_child_directory(client.clone(), directory));
            let directory_helper = DirectoryHelper::new(client.clone());
            let versions = try!(directory_helper.get_versions(child.get_key().get_id(),

                                                              child.get_key().get_type_tag()));
            if versions.is_empty() {
                println!("No directory versions found");
            } else {
                println!("List of directory versions");
                println!("\t No. \t Version Id");
                println!("\t === \t ==========");
                for (i, version) in versions.iter().enumerate() {
................................................................................
                    println!("\t {} \t {:?}", i + 1, format_version_id(&version.0));
                }
            }
        }
        4 => {
            // Delete directory
            let directory_helper = DirectoryHelper::new(client.clone());
            let _ =
                try!(directory_helper.delete(&mut directory, &get_user_string("Directory name")));
            println!("Directory deleted");
        }
        _ => {}
    };
    Ok(())
}

................................................................................
fn file_operation(option: u32,
                  client: Arc<Mutex<Client>>,
                  directory: &mut DirectoryListing)
                  -> Result<(), NfsError> {
    match option {
        5 => {
            // List files
            let child = try!(get_child_directory(client, directory));
            let files = child.get_files();
            if files.is_empty() {
                println!("No Files found in Directory - {}",
                         child.get_metadata().get_name());
            } else {
                println!("List of Files");
                println!("\t        Modified On                Name ");
                println!("\t =========================      ===========");
                for file in files {
                    println!("\t {:?} \t {}",
                             unwrap!(time::strftime("%d-%m-%Y %H:%M UTC",
                                                    &file.get_metadata().get_modified_time())),

                             file.get_name());
                }
            }
        }
        6 => {
            // Create file
            let child = try!(get_child_directory(client.clone(), directory));
            let data = get_user_string("text to be saved as a file").into_bytes();
            let mut file_helper = FileHelper::new(client);

            let mut writer = try!(file_helper.create(get_user_string("File name"), vec![], child));

            try!(writer.write(&data[..]));
            let _ = try!(writer.close());
            println!("File created");
        }
        7 => {
            // Update file
            let child = try!(get_child_directory(client.clone(), directory));
            let file = if let Some(file) = child.find_file(&get_user_string("File name")) {
                file
            } else {
                return Err(NfsError::FileNotFound);
            };
            let data = get_user_string("text to be saved as a file").into_bytes();
            let mut file_helper = FileHelper::new(client);
            let mut writer =
                try!(file_helper.update_content(file.clone(), Mode::Overwrite, child.clone()));
            try!(writer.write(&data[..]));
            let _ = try!(writer.close());
            println!("File Updated");
        }
        8 => {
            // Read file
            let child = try!(get_child_directory(client.clone(), directory));
            let file = if let Some(file) = child.find_file(&get_user_string("File name")) {
                file
            } else {
                return Err(NfsError::FileNotFound);
            };
            let mut file_helper = FileHelper::new(client);
            let mut reader = try!(file_helper.read(file));
            let data_read = try!(reader.read(0, file.get_metadata().get_size()));

            match String::from_utf8(data_read) {
                Ok(data) => {
                    println!("Content Read: ");
                    println!("{}\n", data);
                }
                Err(msg) => println!("Failed: {:?}", msg),
            }
        }
        9 => {
            // Read file by version
            let child = try!(get_child_directory(client.clone(), directory));
            let file_name = get_user_string("File name");


            let file = try!(child.find_file(&file_name).ok_or(NfsError::FileNotFound));
            let mut file_helper = FileHelper::new(client);
            let versions = try!(file_helper.get_versions(&file, &child));
            let ref file_version;
            if versions.len() == 1 {
                file_version = unwrap!(versions.get(0));
            } else {
                println!("Available Versions::");
                for (i, version) in versions.iter().enumerate() {
                    println!("\t{} Modified at {:?}",
                             i + 1,
                             unwrap!(time::strftime("%d-%m-%Y %H:%M UTC",

                                                    &version.get_metadata().get_modified_time())))

                }
                match get_user_string("Number corresponding to the version")
                    .trim()
                    .parse::<usize>() {
                    Ok(index) => {
                        if let Some(version) = versions.get(index - 1) {
                            file_version = version;
                        } else {
                            println!("Invalid version : Fetching latest version");
                            file_version = unwrap!(versions.get(0));
                        }
................................................................................
                    Err(e) => {
                        println!("Invalid input ({}): Fetching latest version", e);
                        file_version = unwrap!(versions.get(0));
                    }
                }
            }

            let mut reader = try!(file_helper.read(file_version));
            let data_read = try!(reader.read(0, file_version.get_metadata().get_size()));

            match String::from_utf8(data_read) {
                Ok(data) => {
                    println!("Content Read: ");
                    println!("{}\n", data);
                }
                Err(msg) => println!("Failed: {:?}", msg),
            }
        }
        10 => {
            // Delete file
            let mut child = try!(get_child_directory(client.clone(), directory));
            let file_helper = FileHelper::new(client);

            let _ = try!(file_helper.delete(get_user_string("File name"), &mut child));
            println!("File deleted");
        }
        11 => {
            // Copy file
            let from_directory = try!(get_child_directory(client.clone(), directory));
            let to_dir_name = get_user_string("Select the Directory to copy file to (Destination \
                                               Directory)");
            let directory_metadata = directory.get_sub_directories();

            if directory_metadata.is_empty() || directory_metadata.len() == 1 {
                println!("No directories found");
                return Ok(());
            } else {
                match directory_metadata.iter()

                    .find(|metadata| *metadata.get_name() == to_dir_name) {
                    Some(to_dir) => {
                        if from_directory.get_key() == to_dir.get_key() {
                            return Err(NfsError::DestinationAndSourceAreSame);
                        }
                        let file_name = &get_user_string("File name");

                        let file = try!(from_directory.find_file(file_name)
                            .ok_or(NfsError::FileNotFound));
                        let directory_helper = DirectoryHelper::new(client);
                        let mut destination = try!(directory_helper.get(to_dir.get_key()));
                        if destination.find_file(file_name).is_some() {
                            return Err(NfsError::FileAlreadyExistsWithSameName);
                        }
                        destination.get_mut_files().push(file.clone());
                        let _ = try!(directory_helper.update(&destination));
                        println!("File copied");
                    }
                    None => println!("Destination Directory not found"),
                }
            }
        }
        _ => {}







|
|







 







<
<
<
<
<
<
<
<







 







>












>
>
>
>


|






|







 







<







 







>
|
|







 







|
>
>







 







>
|
|
|
|
|
|







 







|
|
<
|
|





|

|
>
|







 







|
|







 







|









|
|
|
>






|


>
|

|
|




|







|
|
|
|




|






|
|











|

>
>
|

|






|

|
>
|
>


|
|







 







|
|











|

>
|




|








|
>
|





>
|
|

|




|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
..
27
28
29
30
31
32
33








34
35
36
37
38
39
40
..
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
..
94
95
96
97
98
99
100

101
102
103
104
105
106
107
...
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
...
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
...
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
...
180
181
182
183
184
185
186
187
188

189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
...
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
...
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
...
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
// Copyright 2015 MaidSafe.net limited.
//
// This SAFE Network Software is licensed to you under (1) the MaidSafe.net Commercial License,
// version 1.0 or later, or (2) The General Public License (GPL), version 3, depending on which
// licence you accepted on initial access to the Software (the "Licences").
//
// By contributing code to the SAFE Network Software, or to this project generally, you agree to be
// bound by the terms of the MaidSafe Contributor Agreement.  This, along with the Licenses can be
// found in the root directory of this project at LICENSE, COPYING and CONTRIBUTOR.
//
// Unless required by applicable law or agreed to in writing, the SAFE Network Software distributed
// under the GPL Licence is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied.
//
// Please review the Licences for the specific language governing permissions and limitations
// relating to use of the SAFE Network Software.
................................................................................
        unknown_lints, unsafe_code, unused, unused_allocation, unused_attributes,
        unused_comparisons, unused_features, unused_parens, while_true)]
#![warn(trivial_casts, trivial_numeric_casts, unused_extern_crates, unused_import_braces,
        unused_qualifications, unused_results)]
#![allow(box_pointers, fat_ptr_transmutes, missing_copy_implementations,
         missing_debug_implementations, variant_size_differences)]









extern crate routing;
extern crate safe_core;
#[macro_use]
extern crate unwrap;


use routing::XOR_NAME_LEN;
................................................................................
use safe_core::nfs::helper::file_helper::FileHelper;
use safe_core::nfs::helper::writer::Mode;
use std::sync::{Arc, Mutex};

fn create_account() -> Result<Client, NfsError> {
    let mut secret_0 = String::new();
    let mut secret_1 = String::new();
    let mut invitation = String::new();

    println!("\n\tAccount Creation");
    println!("\t================");

    println!("\n------------ Enter account-locator ---------------");
    let _ = std::io::stdin().read_line(&mut secret_0);
    secret_0 = secret_0.trim().to_string();

    println!("\n------------ Enter password ---------------");
    let _ = std::io::stdin().read_line(&mut secret_1);
    secret_1 = secret_1.trim().to_string();

    println!("\n------------ Enter invitation ---------------");
    let _ = std::io::stdin().read_line(&mut invitation);
    invitation = invitation.trim().to_string();

    // Account Creation
    println!("\nTrying to create an account ...");
    let _ = unwrap!(Client::create_account(&secret_0, &secret_1, &invitation));
    println!("Account Created Successfully !!");
    println!("\n\n\tAuto Account Login");
    println!("\t==================");

    // Log into the created account
    println!("\nTrying to log into the created account using supplied credentials ...");
    let client = Client::log_in(&secret_0, &secret_1)?;
    println!("Account Login Successful !!");
    Ok(client)
}

fn get_root_directory(client: Arc<Mutex<Client>>) -> Result<DirectoryListing, NfsError> {
    let directory_helper = DirectoryHelper::new(client.clone());
    directory_helper.get_user_root_directory_listing()
................................................................................
        println!("{} can not be empty", placeholder);
        println!("------Enter Directory name--------");
        let _ = std::io::stdin().read_line(&mut txt);
    }
    txt
}


fn format_version_id(version_id: &[u8; XOR_NAME_LEN]) -> String {
    let mut version = String::new();
    for byte in &version_id[0..4] {
        version.push_str(&byte.to_string()[..]);
    }
    version.push_str("..");
    for byte in &version_id[(XOR_NAME_LEN - 4)..XOR_NAME_LEN] {
................................................................................
    version
}

fn get_child_directory(client: Arc<Mutex<Client>>,
                       directory: &mut DirectoryListing)
                       -> Result<DirectoryListing, NfsError> {
    let directory_name = &get_user_string("Directory name");
    let directory_metadata = directory
        .find_sub_directory(directory_name)
        .ok_or(NfsError::DirectoryNotFound)?;
    let directory_helper = DirectoryHelper::new(client);

    directory_helper.get(directory_metadata.get_key())
}

fn directory_operation(option: u32,
                       client: Arc<Mutex<Client>>,
................................................................................
        1 => {
            // Create directory
            println!("----------Select the Directory type-----------");
            println!("1. Versioned Private Directory");
            println!("2. Versioned Public Directory");
            println!("3. UnVersioned Private Directory");
            println!("4. UnVersioned Public Directory");
            match get_user_string("number corresponding to the type")
                      .trim()
                      .parse::<usize>() {
                Ok(index) => {
                    if index > 4 {
                        println!("Invalid input");
                        return Ok(());
                    }
                    let name = get_user_string("Directory name");
                    let versioned = match index {
................................................................................
                    let tag_type = if versioned {
                        nfs::VERSIONED_DIRECTORY_LISTING_TAG
                    } else {
                        nfs::UNVERSIONED_DIRECTORY_LISTING_TAG
                    };

                    let directory_helper = DirectoryHelper::new(client.clone());
                    let _ = directory_helper
                        .create(name.clone(),
                                tag_type,
                                vec![],
                                versioned,
                                access_level,
                                Some(&mut directory))?;
                    println!("Created Directory - {}", name);
                }
                Err(_) => println!("Invalid input"),
            };
        }
        2 => {
            // List directories
................................................................................
            let directory_metadata = directory.get_sub_directories();
            if directory_metadata.is_empty() {
                println!("No directories found");
            } else {
                println!("List of directories");
                println!("\t        Created On                  Name ");
                println!("\t =========================       ==========");
                for metadata in directory_metadata {
                    println!("\t {} \t {}",

                             metadata.get_created_time().format("%d-%m-%Y %H:%M UTC"),
                             metadata.get_name());
                }
            }
        }
        3 => {
            // List versions
            let child = get_child_directory(client.clone(), directory)?;
            let directory_helper = DirectoryHelper::new(client.clone());
            let versions =
                directory_helper
                    .get_versions(child.get_key().get_id(), child.get_key().get_type_tag())?;
            if versions.is_empty() {
                println!("No directory versions found");
            } else {
                println!("List of directory versions");
                println!("\t No. \t Version Id");
                println!("\t === \t ==========");
                for (i, version) in versions.iter().enumerate() {
................................................................................
                    println!("\t {} \t {:?}", i + 1, format_version_id(&version.0));
                }
            }
        }
        4 => {
            // Delete directory
            let directory_helper = DirectoryHelper::new(client.clone());
            let _ = directory_helper
                .delete(&mut directory, &get_user_string("Directory name"))?;
            println!("Directory deleted");
        }
        _ => {}
    };
    Ok(())
}

................................................................................
fn file_operation(option: u32,
                  client: Arc<Mutex<Client>>,
                  directory: &mut DirectoryListing)
                  -> Result<(), NfsError> {
    match option {
        5 => {
            // List files
            let child = get_child_directory(client, directory)?;
            let files = child.get_files();
            if files.is_empty() {
                println!("No Files found in Directory - {}",
                         child.get_metadata().get_name());
            } else {
                println!("List of Files");
                println!("\t        Modified On                Name ");
                println!("\t =========================      ===========");
                for file in files {
                    println!("\t {} \t {}",
                             file.get_metadata()
                                 .get_modified_time()
                                 .format("%d-%m-%Y %H:%M UTC"),
                             file.get_name());
                }
            }
        }
        6 => {
            // Create file
            let child = get_child_directory(client.clone(), directory)?;
            let data = get_user_string("text to be saved as a file").into_bytes();
            let mut file_helper = FileHelper::new(client);
            let mut writer = file_helper
                .create(get_user_string("File name"), vec![], child)?;

            writer.write(&data[..])?;
            let _ = writer.close()?;
            println!("File created");
        }
        7 => {
            // Update file
            let child = get_child_directory(client.clone(), directory)?;
            let file = if let Some(file) = child.find_file(&get_user_string("File name")) {
                file
            } else {
                return Err(NfsError::FileNotFound);
            };
            let data = get_user_string("text to be saved as a file").into_bytes();
            let mut file_helper = FileHelper::new(client);
            let mut writer = file_helper
                .update_content(file.clone(), Mode::Overwrite, child.clone())?;
            writer.write(&data[..])?;
            let _ = writer.close()?;
            println!("File Updated");
        }
        8 => {
            // Read file
            let child = get_child_directory(client.clone(), directory)?;
            let file = if let Some(file) = child.find_file(&get_user_string("File name")) {
                file
            } else {
                return Err(NfsError::FileNotFound);
            };
            let mut file_helper = FileHelper::new(client);
            let mut reader = file_helper.read(file)?;
            let data_read = reader.read(0, file.get_metadata().get_size())?;

            match String::from_utf8(data_read) {
                Ok(data) => {
                    println!("Content Read: ");
                    println!("{}\n", data);
                }
                Err(msg) => println!("Failed: {:?}", msg),
            }
        }
        9 => {
            // Read file by version
            let child = get_child_directory(client.clone(), directory)?;
            let file_name = get_user_string("File name");
            let file = child
                .find_file(&file_name)
                .ok_or(NfsError::FileNotFound)?;
            let mut file_helper = FileHelper::new(client);
            let versions = file_helper.get_versions(file, &child)?;
            let ref file_version;
            if versions.len() == 1 {
                file_version = unwrap!(versions.get(0));
            } else {
                println!("Available Versions::");
                for (i, version) in versions.iter().enumerate() {
                    println!("\t{} Modified at {}",
                             i + 1,
                             version
                                 .get_metadata()
                                 .get_modified_time()
                                 .format("%d-%m-%Y %H:%M UTC"))
                }
                match get_user_string("Number corresponding to the version")
                          .trim()
                          .parse::<usize>() {
                    Ok(index) => {
                        if let Some(version) = versions.get(index - 1) {
                            file_version = version;
                        } else {
                            println!("Invalid version : Fetching latest version");
                            file_version = unwrap!(versions.get(0));
                        }
................................................................................
                    Err(e) => {
                        println!("Invalid input ({}): Fetching latest version", e);
                        file_version = unwrap!(versions.get(0));
                    }
                }
            }

            let mut reader = file_helper.read(file_version)?;
            let data_read = reader.read(0, file_version.get_metadata().get_size())?;

            match String::from_utf8(data_read) {
                Ok(data) => {
                    println!("Content Read: ");
                    println!("{}\n", data);
                }
                Err(msg) => println!("Failed: {:?}", msg),
            }
        }
        10 => {
            // Delete file
            let mut child = get_child_directory(client.clone(), directory)?;
            let file_helper = FileHelper::new(client);
            let _ = file_helper
                .delete(get_user_string("File name"), &mut child)?;
            println!("File deleted");
        }
        11 => {
            // Copy file
            let from_directory = get_child_directory(client.clone(), directory)?;
            let to_dir_name = get_user_string("Select the Directory to copy file to (Destination \
                                               Directory)");
            let directory_metadata = directory.get_sub_directories();

            if directory_metadata.is_empty() || directory_metadata.len() == 1 {
                println!("No directories found");
                return Ok(());
            } else {
                match directory_metadata
                          .iter()
                          .find(|metadata| *metadata.get_name() == to_dir_name) {
                    Some(to_dir) => {
                        if from_directory.get_key() == to_dir.get_key() {
                            return Err(NfsError::DestinationAndSourceAreSame);
                        }
                        let file_name = &get_user_string("File name");
                        let file = from_directory
                            .find_file(file_name)
                            .ok_or(NfsError::FileNotFound)?;
                        let directory_helper = DirectoryHelper::new(client);
                        let mut destination = directory_helper.get(to_dir.get_key())?;
                        if destination.find_file(file_name).is_some() {
                            return Err(NfsError::FileAlreadyExistsWithSameName);
                        }
                        destination.get_mut_files().push(file.clone());
                        let _ = directory_helper.update(&destination)?;
                        println!("File copied");
                    }
                    None => println!("Destination Directory not found"),
                }
            }
        }
        _ => {}