Forráskód Böngészése

* patch for #11110, unc drives and forcedirectories from Bart.

git-svn-id: trunk@10855 -
marco 17 éve
szülő
commit
e57c36eaba
1 módosított fájl, 13 hozzáadás és 2 törlés
  1. 13 2
      rtl/objpas/sysutils/sysutils.inc

+ 13 - 2
rtl/objpas/sysutils/sysutils.inc

@@ -533,22 +533,33 @@ var
 function DoForceDirectories(Const Dir: string): Boolean;
 var
   ADir : String;
+  APath: String;
 begin
   Result:=True;
   ADir:=ExcludeTrailingPathDelimiter(Dir);
   if (ADir='') then Exit;
   if Not DirectoryExists(ADir) then
     begin
-    Result:=DoForceDirectories(ExtractFilePath(ADir));
+      APath := ExtractFilePath(ADir);
+      //this can happen on Windows if user specifies Dir like \user\name/test/
+      //and would, if not checked for, cause an infinite recusrsion and a stack overflow
+      if (APath = ADir) then Result := False
+        else Result:=DoForceDirectories(APath);
     If Result then
       Result := CreateDir(ADir);
     end;
 end;
 
+function IsUncDrive(const Drv: String): Boolean;
+begin
+  Result := (Length(Drv) > 2) and (Drv[1] = PathDelim) and (Drv[2] = PathDelim);
+end;
+
 begin
   Result := False;
   ADrv := ExtractFileDrive(Dir);
-  if (ADrv<>'') and (not DirectoryExists(ADrv)) then Exit;
+  if (ADrv<>'') and (not DirectoryExists(ADrv))
+  {$IFNDEF FORCEDIR_NO_UNC_SUPPORT} and (not IsUncDrive(ADrv)){$ENDIF} then Exit;
   if Dir='' then
     begin
       E:=EInOutError.Create(SCannotCreateEmptyDir);