summaryrefslogtreecommitdiff
path: root/crates/vcs_actions/src/actions/virtual_file_actions.rs
blob: 2e6a452b7350c51f184297f97f1ccd67910ce526 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
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
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
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
use std::{
    collections::{HashMap, HashSet},
    path::PathBuf,
    sync::Arc,
};

use action_system::{action::ActionContext, macros::action_gen};
use cfg_file::config::ConfigFile;
use serde::{Deserialize, Serialize};
use tcp_connection::{error::TcpTargetError, instance::ConnectionInstance};
use tokio::sync::Mutex;
use vcs_data::data::{
    local::{
        cached_sheet::CachedSheet, file_status::AnalyzeResult, latest_file_data::LatestFileData,
        local_sheet::LocalMappingMetadata, vault_modified::sign_vault_modified,
    },
    member::MemberId,
    sheet::SheetName,
    vault::virtual_file::{VirtualFileId, VirtualFileVersion, VirtualFileVersionDescription},
};

use crate::actions::{
    auth_member, check_connection_instance, get_current_sheet_name, try_get_local_workspace,
    try_get_vault,
};

pub type NextVersion = String;
pub type UpdateDescription = String;

#[derive(Serialize, Deserialize)]
pub struct TrackFileActionArguments {
    // Path need to track
    pub relative_pathes: HashSet<PathBuf>,

    // File update info
    pub file_update_info: HashMap<PathBuf, (NextVersion, UpdateDescription)>,

    // Print infos
    pub print_infos: bool,
}

#[derive(Serialize, Deserialize)]
pub enum TrackFileActionResult {
    Done {
        created: Vec<PathBuf>,
        updated: Vec<PathBuf>,
        synced: Vec<PathBuf>,
    },

    // Fail
    AuthorizeFailed(String),

    /// There are local move or missing items that have not been resolved,
    /// this situation does not allow track
    StructureChangesNotSolved,

    CreateTaskFailed(CreateTaskResult),
    UpdateTaskFailed(UpdateTaskResult),
    SyncTaskFailed(SyncTaskResult),
}

#[derive(Serialize, Deserialize)]
pub enum CreateTaskResult {
    Success(Vec<PathBuf>), // Success(success_relative_pathes)

    /// Create file on existing path in the sheet
    CreateFileOnExistPath(PathBuf),

    /// Sheet not found
    SheetNotFound(SheetName),
}

#[derive(Serialize, Deserialize)]
pub enum UpdateTaskResult {
    Success(Vec<PathBuf>), // Success(success_relative_pathes)

    VerifyFailed {
        path: PathBuf,
        reason: VerifyFailReason,
    },
}

#[derive(Serialize, Deserialize, Clone)]
pub enum VerifyFailReason {
    SheetNotFound(SheetName),
    MappingNotFound,
    VirtualFileNotFound(VirtualFileId),
    VirtualFileReadFailed(VirtualFileId),
    NotHeld,
    VersionDismatch(VirtualFileVersion, VirtualFileVersion), // (CurrentVersion, RemoteVersion)
    UpdateButNoDescription, // File needs update, but no description exists
    VersionAlreadyExist(VirtualFileVersion), // (RemoteVersion)
}

#[derive(Serialize, Deserialize)]
pub enum SyncTaskResult {
    Success(Vec<PathBuf>), // Success(success_relative_pathes)
}
#[action_gen]
pub async fn track_file_action(
    ctx: ActionContext,
    arguments: TrackFileActionArguments,
) -> Result<TrackFileActionResult, TcpTargetError> {
    let relative_pathes = arguments.relative_pathes;
    let instance = check_connection_instance(&ctx)?;

    // Auth Member
    let member_id = match auth_member(&ctx, instance).await {
        Ok(id) => id,
        Err(e) => return Ok(TrackFileActionResult::AuthorizeFailed(e.to_string())),
    };

    // Check sheet
    let sheet_name = get_current_sheet_name(&ctx, instance, &member_id).await?;

    if ctx.is_proc_on_local() {
        let workspace = try_get_local_workspace(&ctx)?;
        let analyzed = AnalyzeResult::analyze_local_status(&workspace).await?;

        if !analyzed.lost.is_empty() || !analyzed.moved.is_empty() {
            return Ok(TrackFileActionResult::StructureChangesNotSolved);
        }

        let Some(sheet_in_use) = workspace.config().lock().await.sheet_in_use().clone() else {
            return Err(TcpTargetError::NotFound("Sheet not found!".to_string()));
        };

        // Read local sheet and member held
        let local_sheet = workspace.local_sheet(&member_id, &sheet_in_use).await?;
        let cached_sheet = CachedSheet::cached_sheet_data(&sheet_in_use).await?;
        let member_held = LatestFileData::read_from(LatestFileData::data_path(&member_id)?).await?;

        let modified = analyzed
            .modified
            .intersection(&relative_pathes)
            .cloned()
            .collect::<Vec<_>>();

        // Filter out created files
        let created_task = analyzed
            .created
            .intersection(&relative_pathes)
            .cloned()
            .collect::<Vec<_>>();

        // Filter out modified files that need to be updated
        let update_task: Vec<PathBuf> = {
            let result = modified.iter().filter_map(|p| {
                if let (Ok(local_data), Some(cached_data)) =
                    (local_sheet.mapping_data(p), cached_sheet.mapping().get(p))
                {
                    let id = local_data.mapping_vfid();
                    let local_ver = local_data.version_when_updated();
                    if let Some(held_member) = member_held.file_holder(id) {
                        // Check if holder and version match
                        if held_member == &member_id && local_ver == &cached_data.version {
                            return Some(p.clone());
                        }
                    }
                };
                None
            });
            result.collect()
        };

        // Filter out files that do not exist locally or have version inconsistencies and need to be synchronized
        let sync_task: Vec<PathBuf> = {
            let other: Vec<PathBuf> = relative_pathes
                .iter()
                .filter(|p| !created_task.contains(p) && !update_task.contains(p))
                .cloned()
                .collect();

            let result = other.iter().filter_map(|p| {
                // In cached sheet
                let cached_sheet_mapping = cached_sheet.mapping().get(p)?;

                // Check if path mapping at local sheet
                if let Ok(data) = local_sheet.mapping_data(p) {
                    // Version does not match
                    if data.version_when_updated() != &cached_sheet_mapping.version {
                        return Some(p.clone());
                    }

                    // File modified
                    if modified.contains(p) {
                        return Some(p.clone());
                    }
                }

                None
            });
            result.collect()
        };

        // Package tasks
        let tasks: (Vec<PathBuf>, Vec<PathBuf>, Vec<PathBuf>) =
            (created_task, update_task, sync_task);

        // Send to remote
        {
            let mut mut_instance = instance.lock().await;
            mut_instance
                .write_large_msgpack(tasks.clone(), 1024u16)
                .await?;
            // Drop mutex here
        }

        // Process create tasks
        let success_create = match proc_create_tasks_local(
            &ctx,
            instance.clone(),
            &member_id,
            &sheet_name,
            tasks.0,
            arguments.print_infos,
        )
        .await
        {
            Ok(r) => match r {
                CreateTaskResult::Success(relative_pathes) => relative_pathes,
                _ => {
                    return Ok(TrackFileActionResult::CreateTaskFailed(r));
                }
            },
            Err(e) => return Err(e),
        };

        // Process update tasks
        let success_update = match proc_update_tasks_local(
            &ctx,
            instance.clone(),
            &member_id,
            &sheet_name,
            tasks.1,
            arguments.print_infos,
            arguments.file_update_info,
        )
        .await
        {
            Ok(r) => match r {
                UpdateTaskResult::Success(relative_pathes) => relative_pathes,
                _ => {
                    return Ok(TrackFileActionResult::UpdateTaskFailed(r));
                }
            },
            Err(e) => return Err(e),
        };

        // Process sync tasks
        let success_sync = match proc_sync_tasks_local(
            &ctx,
            instance.clone(),
            &member_id,
            &sheet_name,
            tasks.2,
            arguments.print_infos,
        )
        .await
        {
            Ok(r) => match r {
                SyncTaskResult::Success(relative_pathes) => relative_pathes,
            },
            Err(e) => return Err(e),
        };

        if success_create.len() + success_update.len() > 0 {
            sign_vault_modified(true).await;
        }

        return Ok(TrackFileActionResult::Done {
            created: success_create,
            updated: success_update,
            synced: success_sync,
        });
    }

    if ctx.is_proc_on_remote() {
        // Read tasks
        let (created_task, update_task, sync_task): (Vec<PathBuf>, Vec<PathBuf>, Vec<PathBuf>) = {
            let mut mut_instance = instance.lock().await;
            mut_instance.read_large_msgpack(1024u16).await?
        };

        // Process create tasks
        let success_create = match proc_create_tasks_remote(
            &ctx,
            instance.clone(),
            &member_id,
            &sheet_name,
            created_task,
        )
        .await
        {
            Ok(r) => match r {
                CreateTaskResult::Success(relative_pathes) => relative_pathes,
                _ => {
                    return Ok(TrackFileActionResult::CreateTaskFailed(r));
                }
            },
            Err(e) => return Err(e),
        };

        // Process update tasks
        let success_update = match proc_update_tasks_remote(
            &ctx,
            instance.clone(),
            &member_id,
            &sheet_name,
            update_task,
            arguments.file_update_info,
        )
        .await
        {
            Ok(r) => match r {
                UpdateTaskResult::Success(relative_pathes) => relative_pathes,
                _ => {
                    return Ok(TrackFileActionResult::UpdateTaskFailed(r));
                }
            },
            Err(e) => return Err(e),
        };

        // Process sync tasks
        let success_sync = match proc_sync_tasks_remote(
            &ctx,
            instance.clone(),
            &member_id,
            &sheet_name,
            sync_task,
        )
        .await
        {
            Ok(r) => match r {
                SyncTaskResult::Success(relative_pathes) => relative_pathes,
            },
            Err(e) => return Err(e),
        };

        return Ok(TrackFileActionResult::Done {
            created: success_create,
            updated: success_update,
            synced: success_sync,
        });
    }

    Err(TcpTargetError::NoResult("No result.".to_string()))
}

async fn proc_create_tasks_local(
    ctx: &ActionContext,
    instance: Arc<Mutex<ConnectionInstance>>,
    member_id: &MemberId,
    sheet_name: &SheetName,
    relative_paths: Vec<PathBuf>,
    print_infos: bool,
) -> Result<CreateTaskResult, TcpTargetError> {
    let workspace = try_get_local_workspace(ctx)?;
    let mut mut_instance = instance.lock().await;
    let mut local_sheet = workspace.local_sheet(member_id, sheet_name).await?;

    // Wait for remote detection of whether the sheet exists
    let has_sheet = mut_instance.read_msgpack::<bool>().await?;
    if !has_sheet {
        return Ok(CreateTaskResult::SheetNotFound(sheet_name.clone()));
    }

    // Wait for remote detection of whether the file exists
    let (hasnt_duplicate, duplicate_path) = mut_instance.read_msgpack::<(bool, PathBuf)>().await?;
    if !hasnt_duplicate {
        return Ok(CreateTaskResult::CreateFileOnExistPath(duplicate_path));
    }

    let mut success_relative_pathes = Vec::new();

    // Start sending files
    for path in relative_paths {
        let full_path = workspace.local_path().join(&path);

        // Send file
        if mut_instance.write_file(&full_path).await.is_err() {
            continue;
        }

        // Read virtual file id and version
        let (vfid, version, version_desc) = mut_instance
            .read_msgpack::<(
                VirtualFileId,
                VirtualFileVersion,
                VirtualFileVersionDescription,
            )>()
            .await?;

        // Add mapping to local sheet
        let hash = sha1_hash::calc_sha1(&full_path, 2048).await.unwrap().hash;
        let time = std::fs::metadata(&full_path)?.modified()?;
        local_sheet.add_mapping(
            path.clone(),
            LocalMappingMetadata::new(
                hash,                                 // hash_when_updated
                time,                                 // time_when_updated
                std::fs::metadata(&full_path)?.len(), // size_when_updated
                version_desc,                         // version_desc_when_updated
                version,                              // version_when_updated
                vfid,                                 // mapping_vfid
                time,                                 // last_modifiy_check_itme
                false,                                // last_modifiy_check_result
            ),
        )?;

        // Print success info
        if print_infos {
            println!("+ {}", path.display());
        }

        success_relative_pathes.push(path);
    }

    // Write local sheet
    local_sheet.write().await?;

    Ok(CreateTaskResult::Success(success_relative_pathes))
}

async fn proc_create_tasks_remote(
    ctx: &ActionContext,
    instance: Arc<Mutex<ConnectionInstance>>,
    member_id: &MemberId,
    sheet_name: &SheetName,
    relative_paths: Vec<PathBuf>,
) -> Result<CreateTaskResult, TcpTargetError> {
    let vault = try_get_vault(ctx)?;
    let mut mut_instance = instance.lock().await;

    // Sheet check
    let Ok(mut sheet) = vault.sheet(sheet_name).await else {
        // Sheet not found
        mut_instance.write_msgpack(false).await?;
        return Ok(CreateTaskResult::SheetNotFound(sheet_name.to_string()));
    };
    mut_instance.write_msgpack(true).await?;

    // Duplicate create precheck
    for path in relative_paths.iter() {
        if sheet.mapping().contains_key(path) {
            // Duplicate file
            mut_instance.write_msgpack((false, path)).await?;
            return Ok(CreateTaskResult::CreateFileOnExistPath(path.clone()));
        }
    }
    mut_instance.write_msgpack((true, PathBuf::new())).await?;

    let mut success_relative_pathes = Vec::new();

    // Start receiving files
    for path in relative_paths {
        // Read file and create virtual file
        let Ok(vfid) = vault
            .create_virtual_file_from_connection(&mut mut_instance, member_id)
            .await
        else {
            continue;
        };

        // Record virtual file to sheet
        let vf_meta = vault.virtual_file(&vfid)?.read_meta().await?;
        sheet
            .add_mapping(path.clone(), vfid.clone(), vf_meta.version_latest())
            .await?;

        // Tell client the virtual file id and version
        mut_instance
            .write_msgpack((
                vfid,
                vf_meta.version_latest(),
                vf_meta
                    .version_description(vf_meta.version_latest())
                    .unwrap(),
            ))
            .await?;

        success_relative_pathes.push(path);
    }

    sheet.persist().await?;

    Ok(CreateTaskResult::Success(success_relative_pathes))
}

async fn proc_update_tasks_local(
    ctx: &ActionContext,
    instance: Arc<Mutex<ConnectionInstance>>,
    member_id: &MemberId,
    sheet_name: &SheetName,
    relative_paths: Vec<PathBuf>,
    print_infos: bool,
    file_update_info: HashMap<PathBuf, (NextVersion, UpdateDescription)>,
) -> Result<UpdateTaskResult, TcpTargetError> {
    let workspace = try_get_local_workspace(ctx)?;
    let mut mut_instance = instance.lock().await;
    let mut local_sheet = workspace.local_sheet(member_id, sheet_name).await?;

    let mut success = Vec::new();

    for path in relative_paths.iter() {
        let Ok(mapping) = local_sheet.mapping_data(path) else {
            // Is mapping not found, write empty
            mut_instance.write_msgpack("".to_string()).await?;
            continue;
        };
        // Read and send file version
        let Ok(_) = mut_instance
            .write_msgpack(mapping.version_when_updated())
            .await
        else {
            continue;
        };

        // Read verify result
        let verify_result: bool = mut_instance.read_msgpack().await?;
        if !verify_result {
            let reason = mut_instance.read_msgpack::<VerifyFailReason>().await?;
            return Ok(UpdateTaskResult::VerifyFailed {
                path: path.clone(),
                reason: reason.clone(),
            });
        }

        // Calc hash
        let hash_result = match sha1_hash::calc_sha1(workspace.local_path().join(path), 2048).await
        {
            Ok(r) => r,
            Err(_) => {
                mut_instance.write_msgpack(false).await?; // Not Ready
                continue;
            }
        };

        // Get next version
        let Some((next_version, description)) = file_update_info.get(path) else {
            mut_instance.write_msgpack(false).await?; // Not Ready
            continue;
        };

        // Write
        mut_instance.write_msgpack(true).await?; // Ready
        mut_instance.write_file(path).await?;

        // Read upload result
        let upload_result: bool = mut_instance.read_msgpack().await?;
        if upload_result {
            // Success
            let mapping_data_mut = local_sheet.mapping_data_mut(path).unwrap();
            let version = mapping_data_mut.version_when_updated().clone();
            mapping_data_mut.set_hash_when_updated(hash_result.hash);
            mapping_data_mut.set_version_when_updated(next_version.clone());
            mapping_data_mut.set_version_desc_when_updated(VirtualFileVersionDescription {
                creator: member_id.clone(),
                description: description.clone(),
            });
            mapping_data_mut.set_last_modifiy_check_result(false); // Mark file not modified

            // Write
            local_sheet.write().await?;

            // Push path into success vec
            success.push(path.clone());

            // Print success info
            if print_infos {
                println!("* {} ({} -> {})", path.display(), version, next_version);
            }
        }
    }

    Ok(UpdateTaskResult::Success(success))
}

async fn proc_update_tasks_remote(
    ctx: &ActionContext,
    instance: Arc<Mutex<ConnectionInstance>>,
    member_id: &MemberId,
    sheet_name: &SheetName,
    relative_paths: Vec<PathBuf>,
    file_update_info: HashMap<PathBuf, (NextVersion, UpdateDescription)>,
) -> Result<UpdateTaskResult, TcpTargetError> {
    let vault = try_get_vault(ctx)?;
    let mut mut_instance = instance.lock().await;

    let mut success = Vec::new();

    for path in relative_paths.iter() {
        // Read version
        let Ok(version) = mut_instance.read_msgpack::<VirtualFileVersion>().await else {
            continue;
        };
        if version.is_empty() {
            continue;
        }

        // Verify
        let Some((next_version, description)) = file_update_info.get(path) else {
            mut_instance.write_msgpack(false).await?;
            let reason = VerifyFailReason::UpdateButNoDescription;
            mut_instance.write_msgpack(reason.clone()).await?;
            return Ok(UpdateTaskResult::VerifyFailed {
                path: path.clone(),
                reason,
            }); // Sheet not found
        };
        let Ok(mut sheet) = vault.sheet(sheet_name).await else {
            mut_instance.write_msgpack(false).await?;
            let reason = VerifyFailReason::SheetNotFound(sheet_name.clone());
            mut_instance.write_msgpack(reason.clone()).await?;
            return Ok(UpdateTaskResult::VerifyFailed {
                path: path.clone(),
                reason,
            }); // Sheet not found
        };
        let Some(mapping_data) = sheet.mapping_mut().get_mut(path) else {
            mut_instance.write_msgpack(false).await?;
            let reason = VerifyFailReason::MappingNotFound;
            mut_instance.write_msgpack(reason.clone()).await?;
            return Ok(UpdateTaskResult::VerifyFailed {
                path: path.clone(),
                reason,
            }); // Mapping not found
        };
        let Ok(vf) = vault.virtual_file(&mapping_data.id) else {
            mut_instance.write_msgpack(false).await?;
            let reason = VerifyFailReason::VirtualFileNotFound(mapping_data.id.clone());
            mut_instance.write_msgpack(reason.clone()).await?;
            return Ok(UpdateTaskResult::VerifyFailed {
                path: path.clone(),
                reason,
            }); // Virtual file not found
        };
        let Ok(vf_metadata) = vf.read_meta().await else {
            mut_instance.write_msgpack(false).await?;
            let reason = VerifyFailReason::VirtualFileReadFailed(mapping_data.id.clone());
            mut_instance.write_msgpack(reason.clone()).await?;
            return Ok(UpdateTaskResult::VerifyFailed {
                path: path.clone(),
                reason,
            }); // Read virtual file metadata failed
        };
        if vf_metadata.versions().contains(next_version) {
            mut_instance.write_msgpack(false).await?;
            let reason = VerifyFailReason::VersionAlreadyExist(version);
            mut_instance.write_msgpack(reason.clone()).await?;
            return Ok(UpdateTaskResult::VerifyFailed {
                path: path.clone(),
                reason,
            }); // VersionAlreadyExist
        }
        if vf_metadata.hold_member() != member_id {
            mut_instance.write_msgpack(false).await?;
            let reason = VerifyFailReason::NotHeld;
            mut_instance.write_msgpack(reason.clone()).await?;
            return Ok(UpdateTaskResult::VerifyFailed {
                path: path.clone(),
                reason,
            }); // Member not held it
        };
        if mapping_data.version != version {
            mut_instance.write_msgpack(false).await?;
            let reason =
                VerifyFailReason::VersionDismatch(version.clone(), mapping_data.version.clone());
            mut_instance.write_msgpack(reason.clone()).await?;
            return Ok(UpdateTaskResult::VerifyFailed {
                path: path.clone(),
                reason,
            }); // Version does not match
        };
        mut_instance.write_msgpack(true).await?; // Verified

        // Read if local ready
        let ready: bool = mut_instance.read_msgpack().await?;
        if !ready {
            continue;
        }

        // Read and update virtual file
        match vault
            .update_virtual_file_from_connection(
                &mut mut_instance,
                member_id,
                &mapping_data.id,
                next_version,
                VirtualFileVersionDescription {
                    creator: member_id.clone(),
                    description: description.clone(),
                },
            )
            .await
        {
            Ok(_) => {
                // Update version to sheet
                mapping_data.version = next_version.clone();

                // Persist
                sheet.persist().await?;

                success.push(path.clone());
                mut_instance.write_msgpack(true).await?; // Success
            }
            Err(e) => {
                mut_instance.write_msgpack(false).await?; // Fail
                return Err(e.into());
            }
        }
    }

    Ok(UpdateTaskResult::Success(success))
}

async fn proc_sync_tasks_local(
    _ctx: &ActionContext,
    _instance: Arc<Mutex<ConnectionInstance>>,
    _member_id: &MemberId,
    _sheet_name: &SheetName,
    _relative_paths: Vec<PathBuf>,
    _print_infos: bool,
) -> Result<SyncTaskResult, TcpTargetError> {
    Ok(SyncTaskResult::Success(Vec::new()))
}

async fn proc_sync_tasks_remote(
    _ctx: &ActionContext,
    _instance: Arc<Mutex<ConnectionInstance>>,
    _member_id: &MemberId,
    _sheet_name: &SheetName,
    _relative_paths: Vec<PathBuf>,
) -> Result<SyncTaskResult, TcpTargetError> {
    Ok(SyncTaskResult::Success(Vec::new()))
}