diff options
| -rw-r--r-- | fctdrive/src/main.rs | 50 |
1 files changed, 32 insertions, 18 deletions
diff --git a/fctdrive/src/main.rs b/fctdrive/src/main.rs index 0f7c83c..2035680 100644 --- a/fctdrive/src/main.rs +++ b/fctdrive/src/main.rs | |||
| @@ -849,11 +849,42 @@ fn cmd_rename(args: RenameArgs) { | |||
| 849 | write_log_file(&ops); | 849 | write_log_file(&ops); |
| 850 | } | 850 | } |
| 851 | 851 | ||
| 852 | type FsNodeWriter<'a> = std::io::BufWriter<std::io::StdoutLock<'a>>; | ||
| 853 | |||
| 852 | fn cmd_view(args: ViewArgs) { | 854 | fn cmd_view(args: ViewArgs) { |
| 855 | let stdout = std::io::stdout().lock(); | ||
| 856 | let mut writer = BufWriter::new(stdout); | ||
| 853 | let mut fs = Fs::default(); | 857 | let mut fs = Fs::default(); |
| 854 | let ops = read_log_file(); | 858 | let ops = read_log_file(); |
| 855 | ops.iter().for_each(|op| apply(&mut fs, op).unwrap()); | 859 | ops.iter().for_each(|op| apply(&mut fs, op).unwrap()); |
| 856 | write_node(&fs, fs.root, Default::default()); | 860 | write_node(&mut writer, &fs, fs.root, Default::default()); |
| 861 | writer.flush().unwrap(); | ||
| 862 | } | ||
| 863 | |||
| 864 | fn write_node(writer: &mut FsNodeWriter, fs: &Fs, node_id: FsNodeId, path: DrivePath) { | ||
| 865 | let node = &fs.nodes[node_id]; | ||
| 866 | match node.kind { | ||
| 867 | FsNodeKind::File => { | ||
| 868 | write!( | ||
| 869 | writer, | ||
| 870 | "{}\tfile\t{}\t{}\t{}", | ||
| 871 | path, node.lastmod, node.blob, node.author | ||
| 872 | ) | ||
| 873 | .unwrap(); | ||
| 874 | } | ||
| 875 | FsNodeKind::Directory => { | ||
| 876 | write!( | ||
| 877 | writer, | ||
| 878 | "{}\tdir\t{}\t-\t{}", | ||
| 879 | path, node.lastmod, node.author | ||
| 880 | ) | ||
| 881 | .unwrap(); | ||
| 882 | for (child_comp, child_id) in node.children.iter() { | ||
| 883 | let child_path = path.push(child_comp.clone()); | ||
| 884 | write_node(writer, fs, *child_id, child_path); | ||
| 885 | } | ||
| 886 | } | ||
| 887 | } | ||
| 857 | } | 888 | } |
| 858 | 889 | ||
| 859 | #[derive(Debug, Clone)] | 890 | #[derive(Debug, Clone)] |
| @@ -954,23 +985,6 @@ fn collect_all_file_paths(root: &Path) -> Vec<PathBuf> { | |||
| 954 | files | 985 | files |
| 955 | } | 986 | } |
| 956 | 987 | ||
| 957 | fn write_node(fs: &Fs, node_id: FsNodeId, path: DrivePath) { | ||
| 958 | let node = &fs.nodes[node_id]; | ||
| 959 | match node.kind { | ||
| 960 | FsNodeKind::File => println!( | ||
| 961 | "{}\tfile\t{}\t{}\t{}", | ||
| 962 | path, node.lastmod, node.blob, node.author | ||
| 963 | ), | ||
| 964 | FsNodeKind::Directory => { | ||
| 965 | println!("{}\tdir\t{}\t-\t{}", path, node.lastmod, node.author); | ||
| 966 | for (child_comp, child_id) in node.children.iter() { | ||
| 967 | let child_path = path.push(child_comp.clone()); | ||
| 968 | write_node(fs, *child_id, child_path); | ||
| 969 | } | ||
| 970 | } | ||
| 971 | } | ||
| 972 | } | ||
| 973 | |||
| 974 | fn read_log_file() -> Vec<Operation> { | 988 | fn read_log_file() -> Vec<Operation> { |
| 975 | let mut operations = Vec::default(); | 989 | let mut operations = Vec::default(); |
| 976 | if std::fs::exists("log.txt").unwrap() { | 990 | if std::fs::exists("log.txt").unwrap() { |
