Uploaded image for project: 'Flink'
  1. Flink
  2. FLINK-15244

FileUtils#deleteDirectoryQuietly will delete files in the symbolic link which point to a directory

    XMLWordPrintableJSON

Details

    Description

      FileUtils.deleteDirectoryQuietly will delete files in symbolic link which point to a directory. Currently the PyFlink uses this method to delete temporary folders generated during the job submission and python UDF execution, which contains the symbolic links which may point to users' libraries and directories in distributed cache. 

      To resolve this problem we need to check if the directory is symbolic link in FileUtils.deleteDirectoryInternal:

      private static void deleteDirectoryInternal(File directory) throws IOException {
          // **We should check if the directory is symbolic link.**
          if (directory.isDirectory()) {
            // directory exists and is a directory
      
            // empty the directory first
            try {
               cleanDirectoryInternal(directory);
            }
            catch (FileNotFoundException ignored) {
               // someone concurrently deleted the directory, nothing to do for us
               return;
            }
      
            // delete the directory. this fails if the directory is not empty, meaning
            // if new files got concurrently created. we want to fail then.
            // if someone else deleted the empty directory concurrently, we don't mind
            // the result is the same for us, after all
            Files.deleteIfExists(directory.toPath());
         }
         else if (directory.exists()) {
            // exists but is file, not directory
            // either an error from the caller, or concurrently a file got created
            throw new IOException(directory + " is not a directory");
         }
         // else: does not exist, which is okay (as if deleted)
      }
      
      

      Attachments

        Issue Links

          Activity

            People

              weizhong Wei Zhong
              zhongwei Wei Zhong
              Votes:
              1 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 10m
                  10m