Commits

Sebastian Sdorra  committed ae2263b Merge

merge with branch issue-476

  • Participants
  • Parent commits cdea9e7, 651c571
  • Branches issue-500

Comments (0)

Files changed (4)

File scm-core/src/main/java/sonia/scm/util/IOUtil.java

   }
 
   /**
-   *   Method description
+   * Method description
    *
    *
-   *   @param file
+   * @param file
    * @param silent
    *
-   *   @throws IOException
+   * @throws IOException
    */
   public static void delete(File file, boolean silent) throws IOException
   {
       {
         for (File child : children)
         {
-          delete(child);
+          delete(child, silent);
         }
       }
     }
 
-    if (!file.delete())
+    for (int i = 20; !file.delete(); i--)
     {
-      String message = "could not delete file ".concat(file.getPath());
+      if (i <= 20)
+      {
+        String message = "could not delete file ".concat(file.getPath());
 
-      if (silent)
+        if (silent)
+        {
+          logger.error(message);
+        }
+        else
+        {
+          throw new IOException(message);
+        }
+      }
+
+      try
       {
-        logger.error(message);
+        logger.warn("sleep 250ms, because of delete for file {} failed", file);
+        Thread.sleep(250);
       }
-      else
+      catch (InterruptedException ex)
       {
-        throw new IOException(message);
+        logger.warn("sleep of delete method interrupted", ex);
       }
     }
   }

File scm-core/src/main/java/sonia/scm/util/ValidationUtil.java

     "^[A-z0-9][\\w.-]*@[A-z0-9][\\w\\-\\.]+\\.[A-z0-9]{2,6}$";
 
   /** Field description */
-  private static final String REGEX_NAME = "^[A-z0-9\\.\\-_]+$";
+  private static final String REGEX_NAME =
+    "^[A-z0-9\\.\\-_@]|[^ ]([A-z0-9\\.\\-_@ ]*[A-z0-9\\.\\-_@]|[^ ])?$";
 
   /** Field description */
   private static final String REGEX_REPOSITORYNAME =
     "(?!^\\.\\.$)(?!^\\.$)(?!.*[\\\\\\[\\]])^[A-z0-9\\.][A-z0-9\\.\\-_/]*$";
 
-  /** Field description */
-  private static final String REGEX_USERNAME =
-    "^[A-z0-9\\.\\-_@]|[^ ]([A-z0-9\\.\\-_@ ]*[A-z0-9\\.\\-_@]|[^ ])?$";
-
   //~--- constructors ---------------------------------------------------------
 
   /**
    * @param username
    *
    * @return
+   * @deprecated use {@link #isNameValid(String)}
    */
+  @Deprecated
   public static boolean isUsernameValid(String username)
   {
-    return Util.isNotEmpty(username) && username.matches(REGEX_USERNAME);
+    return isNameValid(username);
   }
 
   /**

File scm-core/src/test/java/sonia/scm/util/ValidationUtilTest.java

     assertTrue(ValidationUtil.isNameValid("test.git"));
     assertTrue(ValidationUtil.isNameValid("Test123.git"));
     assertTrue(ValidationUtil.isNameValid("Test123-git"));
-    assertTrue(ValidationUtil.isNameValid("Test_repository-123.git"));
+    assertTrue(ValidationUtil.isNameValid("Test_user-123.git"));
+    assertTrue(ValidationUtil.isNameValid("test@scm-manager.de"));
+    assertTrue(ValidationUtil.isNameValid("test 123"));
+    assertTrue(ValidationUtil.isNameValid("t"));
 
     // false
-    assertFalse(ValidationUtil.isNameValid("test 123"));
-    assertFalse(ValidationUtil.isNameValid("test@123"));
+    assertFalse(ValidationUtil.isNameValid(" test 123"));
+    assertFalse(ValidationUtil.isNameValid(" test 123 "));
+    assertFalse(ValidationUtil.isNameValid("test 123 "));
     assertFalse(ValidationUtil.isNameValid("test/123"));
     assertFalse(ValidationUtil.isNameValid("test%123"));
     assertFalse(ValidationUtil.isNameValid("test:123"));
+    assertFalse(ValidationUtil.isNameValid("t "));
+    assertFalse(ValidationUtil.isNameValid(" t"));
+    assertFalse(ValidationUtil.isNameValid(" t "));
   }
 
   /**
       assertFalse(ValidationUtil.isRepositoryNameValid(path));
     }
   }
-
-  /**
-   * Method description
-   *
-   */
-  @Test
-  public void testIsUsernameValid()
-  {
-
-    // true
-    assertTrue(ValidationUtil.isUsernameValid("test"));
-    assertTrue(ValidationUtil.isUsernameValid("test.git"));
-    assertTrue(ValidationUtil.isUsernameValid("Test123.git"));
-    assertTrue(ValidationUtil.isUsernameValid("Test123-git"));
-    assertTrue(ValidationUtil.isUsernameValid("Test_user-123.git"));
-    assertTrue(ValidationUtil.isUsernameValid("test@scm-manager.de"));
-    assertTrue(ValidationUtil.isUsernameValid("test 123"));
-    assertTrue(ValidationUtil.isUsernameValid("t"));
-
-    // false
-    assertFalse(ValidationUtil.isUsernameValid(" test 123"));
-    assertFalse(ValidationUtil.isUsernameValid(" test 123 "));
-    assertFalse(ValidationUtil.isUsernameValid("test 123 "));
-    assertFalse(ValidationUtil.isUsernameValid("test/123"));
-    assertFalse(ValidationUtil.isUsernameValid("test%123"));
-    assertFalse(ValidationUtil.isUsernameValid("test:123"));
-    assertFalse(ValidationUtil.isUsernameValid("t "));
-    assertFalse(ValidationUtil.isUsernameValid(" t"));
-    assertFalse(ValidationUtil.isUsernameValid(" t "));
-  }
 }

File scm-webapp/src/main/webapp/resources/js/override/ext.form.vtypes.js

   // name validator
   
   name: function(val){
-    return /^[A-z0-9\.\-_]+$/.test(val);
+    return val.match(/^[^ ][A-z0-9\.\-_@ ]*[^ ]$/);
   },
   
   nameText: 'The name is invalid.',
   // username validator
   
   username: function(val){
-    return val.match(/^[^ ][A-z0-9\.\-_@ ]*[^ ]$/);
+    return name(val);
   },
   
   usernameText: 'The username is invalid.'