View Issue Details

IDProjectCategoryView StatusLast Update
0024415LazarusLazUtilspublic2013-05-15 07:40
ReporterkhvaleraAssigned ToBart Broersma 
PriorityurgentSeveritymajorReproducibilityalways
Status resolvedResolutionfixed 
Platformi686, x86_64OSAgiliaLinuxOS Version8.1.1
Product Version1.0.8Product Build 
Target VersionFixed in Version1.1 (SVN) 
Summary0024415: Directory is not deleted if it has at least one link
DescriptionFunction DeleteDirectory of fileutil.inc, are not deleted directory if in it there is at least one link
TagsDeleteDirectory
Fixed in Revisionr41159
LazTarget-
WidgetsetGTK 2
Attached Files
  • deldirsymlink.patch (1,211 bytes)
    --- ./DeleteDirectory/fileutil.inc_old	2013-03-26 23:21:52.000000000 +0300
    +++ ./DeleteDirectory/fileutil.inc	2013-05-11 01:08:36.305125632 +0300
    @@ -685,13 +685,13 @@
     begin
       Result:=false;
       CurSrcDir:=CleanAndExpandDirectory(DirectoryName);
    -  if FindFirstUTF8(CurSrcDir+GetAllFilesMask,faAnyFile,FileInfo)=0 then begin
    +  if FindFirstUTF8(CurSrcDir+GetAllFilesMask,faAnyFile {$ifdef unix} or faSymLink {$endif unix},FileInfo)=0 then begin
         repeat
           // check if special file
           if (FileInfo.Name='.') or (FileInfo.Name='..') or (FileInfo.Name='') then
             continue;
           CurFilename:=CurSrcDir+FileInfo.Name;
    -      if (FileInfo.Attr and faDirectory)>0 then begin
    +      if (FileInfo.Attr and faDirectory)>0 {$ifdef unix} and ((FileInfo.Attr and faSymLink)=0) {$endif unix} then begin
             if not DeleteDirectory(CurFilename,false) then exit;
           end else begin
             if not DeleteFileUTF8(CurFilename) then exit;
    @@ -699,7 +699,7 @@
         until FindNextUTF8(FileInfo)<>0;
       end;
       FindCloseUTF8(FileInfo);
    -  if (not OnlyChilds) and (not RemoveDirUTF8(DirectoryName)) then exit;
    +  if (not OnlyChilds) and (not RemoveDirUTF8(CurSrcDir)) then exit;
       Result:=true;
     end;
     
    
    deldirsymlink.patch (1,211 bytes)

Activities

khvalera

2013-05-11 00:25

reporter  

deldirsymlink.patch (1,211 bytes)
--- ./DeleteDirectory/fileutil.inc_old	2013-03-26 23:21:52.000000000 +0300
+++ ./DeleteDirectory/fileutil.inc	2013-05-11 01:08:36.305125632 +0300
@@ -685,13 +685,13 @@
 begin
   Result:=false;
   CurSrcDir:=CleanAndExpandDirectory(DirectoryName);
-  if FindFirstUTF8(CurSrcDir+GetAllFilesMask,faAnyFile,FileInfo)=0 then begin
+  if FindFirstUTF8(CurSrcDir+GetAllFilesMask,faAnyFile {$ifdef unix} or faSymLink {$endif unix},FileInfo)=0 then begin
     repeat
       // check if special file
       if (FileInfo.Name='.') or (FileInfo.Name='..') or (FileInfo.Name='') then
         continue;
       CurFilename:=CurSrcDir+FileInfo.Name;
-      if (FileInfo.Attr and faDirectory)>0 then begin
+      if (FileInfo.Attr and faDirectory)>0 {$ifdef unix} and ((FileInfo.Attr and faSymLink)=0) {$endif unix} then begin
         if not DeleteDirectory(CurFilename,false) then exit;
       end else begin
         if not DeleteFileUTF8(CurFilename) then exit;
@@ -699,7 +699,7 @@
     until FindNextUTF8(FileInfo)<>0;
   end;
   FindCloseUTF8(FileInfo);
-  if (not OnlyChilds) and (not RemoveDirUTF8(DirectoryName)) then exit;
+  if (not OnlyChilds) and (not RemoveDirUTF8(CurSrcDir)) then exit;
   Result:=true;
 end;
 
deldirsymlink.patch (1,211 bytes)

Juha Manninen

2013-05-11 11:24

developer   ~0067637

Your patch cannot be applied in trunk. All changes happen in trunk and thus patches should be created against it.

BTW, your patch also has a strange directory structure, although it does not prevent applying :
 --- ./DeleteDirectory/fileutil.inc_old 2013-03-26 23:21:52.000000000 +0300
 +++ ./DeleteDirectory/fileutil.inc 2013-05-11 01:08:36.305125632 +0300

There is no "DeleteDirectory" in Lazarus sources. Applying must then use:
 $ cd components/lazutils
 $ patch -p2 < ~/patch/deldirsymlink.patch

About the patch itself: Usually cross-platform code in FileUtil is divided to 2 include files:
  {$i winfileutil.inc}
  {$i unixfileutil.inc}

In this case only a minor cross-platform modification is needed and you can do it in fileutil.inc as well.
Then you must refactor a bit, the code is unnecessarily messy now.
For example use a const :

const
  DeleteMask = faAnyFile {$ifdef unix} or faSymLink {$endif unix};

khvalera

2013-05-11 22:13

reporter   ~0067655

The patch I brought for clarity and beauty can do yourself

Bart Broersma

2013-05-12 20:17

developer   ~0067675

Modified patch applied.
In future it would be nice if you could adapt your patches if you are asked to do so by a developer.
Changes are they will be applied much sooner.

Please close if OK.

Issue History

Date Modified Username Field Change
2013-05-11 00:25 khvalera New Issue
2013-05-11 00:25 khvalera File Added: deldirsymlink.patch
2013-05-11 11:24 Juha Manninen LazTarget => -
2013-05-11 11:24 Juha Manninen Note Added: 0067637
2013-05-11 11:24 Juha Manninen Status new => feedback
2013-05-11 21:18 khvalera Tag Attached: DeleteDirectory
2013-05-11 22:13 khvalera Note Added: 0067655
2013-05-11 22:13 khvalera Status feedback => new
2013-05-12 20:17 Bart Broersma Fixed in Revision => r41159
2013-05-12 20:17 Bart Broersma Note Added: 0067675
2013-05-12 20:17 Bart Broersma Status new => resolved
2013-05-12 20:17 Bart Broersma Fixed in Version => 1.1 (SVN)
2013-05-12 20:17 Bart Broersma Resolution open => fixed
2013-05-12 20:17 Bart Broersma Assigned To => Bart Broersma