diff src/org/tmatesoft/hg/internal/StoragePathHelper.java @ 346:6d2c6b2469fc

Issue 18: Invalid storage path for certain long names
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Tue, 22 Nov 2011 04:02:37 +0100
parents a415fe296a50
children 464b4404e75d
line wrap: on
line diff
--- a/src/org/tmatesoft/hg/internal/StoragePathHelper.java	Tue Nov 22 03:14:40 2011 +0100
+++ b/src/org/tmatesoft/hg/internal/StoragePathHelper.java	Tue Nov 22 04:02:37 2011 +0100
@@ -141,7 +141,16 @@
 				int left = MAX_PATH_LEN - sb2.length() - 40 /*digest.length()*/ - STR_DH.length() - ".i".length();
 				assert left >= 0;
 				fnameStart++; // move from / to actual name
-				sb2.append(sb, fnameStart, fnameStart + left > sb.length() ? sb.length() : fnameStart+left);
+				if (fnameStart + left > sb.length()) {
+					// there left less chars in the mangled name that we can fit
+					sb2.append(sb, fnameStart, sb.length());
+					int stillAvailable = (fnameStart+left) - sb.length();
+					// stillAvailable > 0;
+					sb2.append(".i", 0, stillAvailable > 2 ? 2 : stillAvailable);
+				} else {
+					// add as much as we can
+					sb2.append(sb, fnameStart, fnameStart+left);
+				}
 				completeHashName.append(sb2);
 			}
 			completeHashName.append(digest);