[EGIT PATCH 21/31] Add canCreateSubdir() heuristic in CloneDestinationPage

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This method provide user with live-feedback when chosen subdirectory
can't be created for sure.

This is only a heuristic (may produce false-positive errors), as it is
problematic to handle File#canWrite() noisy return values for Windows'
Java.

Signed-off-by: Marek Zawirski <marek.zawirski@xxxxxxxxx>
---
 .../ui/internal/clone/CloneDestinationPage.java    |   23 ++++++++++++++++++-
 1 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/clone/CloneDestinationPage.java b/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/clone/CloneDestinationPage.java
index 01bf54a..e1e9858 100644
--- a/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/clone/CloneDestinationPage.java
+++ b/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/clone/CloneDestinationPage.java
@@ -220,9 +220,17 @@ class CloneDestinationPage extends WizardPage {
 			setPageComplete(false);
 			return;
 		}
-		if (new File(dstpath).exists()) {
+		final File dstFile = new File(dstpath);
+		if (dstFile.exists()) {
 			setErrorMessage(NLS.bind(UIText.CloneDestinationPage_errorExists,
-					new File(dstpath).getName()));
+					dstFile.getName()));
+			setPageComplete(false);
+			return;
+		}
+		final File absoluteFile = dstFile.getAbsoluteFile();
+		if (!canCreateSubdir(absoluteFile.getParentFile())) {
+			setErrorMessage(NLS.bind(UIText.GitCloneWizard_errorCannotCreate,
+					dstFile.getPath()));
 			setPageComplete(false);
 			return;
 		}
@@ -243,6 +251,17 @@ class CloneDestinationPage extends WizardPage {
 		setPageComplete(true);
 	}
 
+	// this is actually just an optimistic heuristic - should be named
+	// isThereHopeThatCanCreateSubdir() as probably there is no 100% reliable
+	// way to check that in Java for Windows
+	private static boolean canCreateSubdir(final File parent) {
+		if (parent == null)
+			return true;
+		if (parent.exists())
+			return parent.isDirectory() && parent.canWrite();
+		return canCreateSubdir(parent.getParentFile());
+	}
+
 	private void revalidate() {
 		if (sourcePage.selectionEquals(validatedRepoSelection)
 				&& branchPage.selectionEquals(validatedSelectedBranches,
-- 
1.5.6.3

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux