Skip to content
This repository has been archived by the owner on Mar 25, 2023. It is now read-only.

fpm revert #360

Merged
merged 2 commits into from
Aug 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 6 additions & 12 deletions src/apis/sync2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ pub(crate) async fn sync_worker(request: SyncRequest) -> fpm::Result<SyncRespons
Default::default();
let mut synced_files = std::collections::HashMap::new();
for file in request.files {
dbg!(&file);
match &file {
SyncRequestFile::Add { path, content } => {
// TODO: We need to check if, file is already available on server
Expand Down Expand Up @@ -250,30 +249,25 @@ pub(crate) async fn sync_worker(request: SyncRequest) -> fpm::Result<SyncRespons
}
}
}
dbg!(&file_list, &server_history);

fpm::history::insert_into_history(&config.root, &file_list, &mut server_history).await?;

dbg!("insert_into_history done");

let server_latest =
fpm::history::FileHistory::get_latest_file_edits(server_history.as_slice())?;
dbg!("1");

let client_history = fpm::history::FileHistory::from_ftd(request.history.as_str())?;
let client_latest =
fpm::history::FileHistory::get_latest_file_edits(client_history.as_slice())?;
dbg!("2");

client_current_files(&config, &server_latest, &client_latest, &mut synced_files).await?;
dbg!("3");

let history_files = client_history_files(&config, &server_latest, &client_latest).await?;
dbg!("4");
let r = SyncResponse {

Ok(SyncResponse {
files: synced_files.into_values().collect_vec(),
dot_history: history_files,
latest_ftd: tokio::fs::read_to_string(config.history_file()).await?,
};
dbg!("5");
Ok(r)
})
}

async fn client_history_files(
Expand Down
2 changes: 1 addition & 1 deletion src/commands/resolve_conflict.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub async fn resolve_conflict(
if number_of_times_flag_used > 1 {
return fpm::usage_error("AmbiguousOptionError: Use only one flag".to_string());
}
let get_files_status = fpm::sync_utils::get_files_status(config).await?;
let get_files_status = config.get_files_status().await?;
let file_status =
if let Some(file_status) = get_files_status.iter().find(|v| v.get_file_path().eq(path)) {
file_status
Expand Down
45 changes: 44 additions & 1 deletion src/commands/revert.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,47 @@
use itertools::Itertools;

pub async fn revert(config: &fpm::Config, path: &str) -> fpm::Result<()> {
let mut workspace: std::collections::BTreeMap<String, fpm::workspace::WorkspaceEntry> = config
.read_workspace()
.await?
.iter()
.map(|v| (v.filename.to_string(), v.clone()))
.collect();
let get_files_status = config
.get_files_status_with_workspace(&mut workspace)
.await?;
let file_status =
if let Some(file_status) = get_files_status.iter().find(|v| v.get_file_path().eq(path)) {
file_status
} else {
config
.write_workspace(workspace.into_values().collect_vec().as_slice())
.await?;
return Err(fpm::Error::UsageError {
message: format!("{} not found", path),
});
};

if let Some(server_version) = file_status.get_latest_version() {
let server_path = config.history_path(path, server_version);
let content = tokio::fs::read(&server_path).await?;
fpm::utils::update(&config.root.join(path), content.as_slice()).await?;
if let Some(workspace_entry) = workspace.get_mut(path) {
workspace_entry.version = Some(server_version);
workspace_entry.deleted = None;
}
} else {
// in case of new file added
tokio::fs::remove_file(path).await?;
workspace.remove(path);
}
config
.write_workspace(workspace.into_values().collect_vec().as_slice())
.await?;
Ok(())
}

/*pub async fn revert_(config: &fpm::Config, path: &str) -> fpm::Result<()> {
use itertools::Itertools;

let mut workspaces = fpm::snapshot::get_workspace(config).await?;
Expand Down Expand Up @@ -36,4 +79,4 @@ pub async fn revert(config: &fpm::Config, path: &str) -> fpm::Result<()> {
}

Ok(())
}
}*/
5 changes: 3 additions & 2 deletions src/commands/sync2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ pub async fn sync2(config: &fpm::Config, files: Option<Vec<String>>) -> fpm::Res
.map(|v| (v.filename.to_string(), v.clone()))
.collect();
let changed_files = {
let mut changed_files =
fpm::sync_utils::get_files_status_with_workspace(config, &mut workspace).await?;
let mut changed_files = config
.get_files_status_with_workspace(&mut workspace)
.await?;
if let Some(ref files) = files {
changed_files = changed_files
.into_iter()
Expand Down
2 changes: 1 addition & 1 deletion src/commands/sync_status.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use itertools::Itertools;

pub async fn sync_status(config: &fpm::Config, source: Option<&str>) -> fpm::Result<()> {
let get_files_status = fpm::sync_utils::get_files_status(config).await?;
let get_files_status = config.get_files_status().await?;
if let Some(source) = source {
if let Some(file_status) = get_files_status
.iter()
Expand Down
4 changes: 0 additions & 4 deletions src/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,6 @@ impl Workspace {
pub(crate) fn set_abort(&mut self) {
self.workspace = WorkspaceType::AbortMerge;
}

pub(crate) fn set_revert(&mut self) {
self.workspace = WorkspaceType::Revert;
}
}

pub(crate) async fn resolve_workspace(
Expand Down
Loading