Browse Source

Check whether new synchronized directories exist and are empty.

Mathias Gottschlag 4 years ago
parent
commit
28517cd188
2 changed files with 16 additions and 4 deletions
  1. 2
    0
      src/bin/cli.rs
  2. 14
    4
      src/bin/client.rs

+ 2
- 0
src/bin/cli.rs View File

28
         // TODO: Login information.
28
         // TODO: Login information.
29
         local_directory: PathBuf,
29
         local_directory: PathBuf,
30
         remote_url: String,
30
         remote_url: String,
31
+        #[structopt(short, long)]
32
+        force: bool,
31
     },
33
     },
32
     RemoveDirectory {
34
     RemoveDirectory {
33
         local_directory: PathBuf,
35
         local_directory: PathBuf,

+ 14
- 4
src/bin/client.rs View File

52
         errors: mpsc::Sender<SynchronizationError>,
52
         errors: mpsc::Sender<SynchronizationError>,
53
     ) -> Result<SynchronizedDirectory, Error> {
53
     ) -> Result<SynchronizedDirectory, Error> {
54
         // TODO: First, connect to the server and test whether we can access the URL?
54
         // TODO: First, connect to the server and test whether we can access the URL?
55
-        // At this point, the directory is still paused.
56
-        // TODO: Return an error if the directory is not empty (unless the user specified an
57
-        // override option).
55
+        // Probably not possible, at this point the directory is still paused.
58
         let file_tree = Arc::new(Mutex::new(FileTree::create(
56
         let file_tree = Arc::new(Mutex::new(FileTree::create(
59
             database, directory, remote_url,
57
             database, directory, remote_url,
60
         )?));
58
         )?));
157
                                 stream.write_all(&(-1i32).to_be_bytes()).await.ok();
155
                                 stream.write_all(&(-1i32).to_be_bytes()).await.ok();
158
                                 stream.write_all(&output).await.ok();
156
                                 stream.write_all(&output).await.ok();
159
                                 stream
157
                                 stream
160
-                                    .write_all(format!("Error: {:?}", e).as_bytes())
158
+                                    .write_all(format!("Error: {}\n", e).as_bytes())
161
                                     .await
159
                                     .await
162
                                     .ok();
160
                                     .ok();
163
                             }
161
                             }
239
         cli::Command::AddDirectory {
237
         cli::Command::AddDirectory {
240
             local_directory,
238
             local_directory,
241
             remote_url,
239
             remote_url,
240
+            force,
242
         } => {
241
         } => {
242
+            if !local_directory.exists() || !local_directory.is_dir() {
243
+                return Err(Error::InvalidParam(
244
+                    "the specified local path does not exist or is no directory".to_owned(),
245
+                ));
246
+            }
247
+            if local_directory.read_dir()?.next().is_some() && !force {
248
+                return Err(Error::InvalidParam(
249
+                    "the specified local directory is not empty (use --force to add the directory)"
250
+                        .to_owned(),
251
+                ));
252
+            }
243
             let local_directory = fs::canonicalize(local_directory)?;
253
             let local_directory = fs::canonicalize(local_directory)?;
244
             // We need to check that we are not synchronizing directories that are within
254
             // We need to check that we are not synchronizing directories that are within
245
             // other synchronized directories.
255
             // other synchronized directories.

Loading…
Cancel
Save