#575 Issue closed: remove temp dir

Labels: enhancement

goldzahn opened issue at 2015-04-14 13:50:

Hi,

on every server I have the problem that
/tmp/rear.XXXXXXXXX/outputfs/servername/ is not empty,
because of the file ".lockfile", so rmdir is never successful (see #298)

The solution of #298 was to add rm -Rf $BUILD_DIR/outputfs
in function cleanup_build_area_and_end_program()
in usr/share/rear/lib/framework-functions.sh
but this lead to problems mentioned in #465,
so it was changed to rmdir $v $BUILD_DIR/outputfs >&2

Looking at function cleanup_build_area_and_end_program() in usr/share/rear/lib/framework-functions.sh:

...
   # line below put in comment due to issue #465
   #rm -Rf $BUILD_DIR/outputfs
   rmdir $v $BUILD_DIR/outputfs >&2
   # in worst case it could not umount; so before remove the BUILD_DIR check if above outputfs is  gone
   mount | grep -q "$BUILD_DIR/outputfs"
   if [[ $? -eq 0 ]]; then
      # still mounted it seems
      LogPrint "Directory $BUILD_DIR/outputfs still mounted - trying lazy umount"  
      sleep 2
      umount -f -l $BUILD_DIR/outputfs >&2
      rmdir $v $BUILD_DIR/outputfs >&2
   fi
   rmdir $v $BUILD_DIR >&2
fi
Log "End of program reached"

Wouldn't it be better to drop the first
rmdir $v $BUILD_DIR/outputfs >&2
and to add
rm -Rf $BUILD_DIR/outputfs
in case $BUILD_DIR/outputfs is not mounted?

... 
   # line below put in comment due to issue #465
   #rm -Rf $BUILD_DIR/outputfs
   # in worst case it could not umount; so before remove the BUILD_DIR check if above outputfs is gone
   mount | grep -q "$BUILD_DIR/outputfs"
   if [[ $? -eq 0 ]]; then
        # still mounted it seems
        LogPrint "Directory $BUILD_DIR/outputfs still mounted - trying lazy umount"
        sleep 2
        umount -f -l $BUILD_DIR/outputfs >&2
        rmdir $v $BUILD_DIR/outputfs >&2
   else 
        # not mounted so we can safely delete $BUILD_DIR/outputfs
        rm -Rf $BUILD_DIR/outputfs
   fi
   rmdir $v $BUILD_DIR >&2
fi
Log "End of program reached"

So if $BUILD_DIR/outputfs is not mounted,
then rm -Rf $BUILD_DIR/outputfs can safely be used,
otherwise rmdir $v $BUILD_DIR/outputfs would be used.

What do you think?

Regards
goldzahn

gdha commented at 2015-04-20 09:32:

@goldzahn good thinking - why not. Will you prepare a pull request for this? Thank you for your proposal of a proper fix for the issues around the cleanup of the temporary directory

gdha commented at 2015-05-31 15:46:

@goldzahn Can we close this issue?

goldzahn commented at 2015-06-02 09:29:

@gdha Sure.
Regards
goldzahn


[Export of Github issue for rear/rear.]