Class TrashPolicyDefault

All Implemented Interfaces:
Configurable

@Private @Evolving public class TrashPolicyDefault extends TrashPolicy
Provides a trash feature. Files are moved to a user's trash directory, a subdirectory of their home directory named ".Trash". Files are initially moved to a current sub-directory of the trash directory. Within that sub-directory their original path is preserved. Periodically one may checkpoint the current trash and remove older checkpoints. (This design permits trash management without enumeration of the full trash content, without date support in the filesystem, and without clock synchronization.)
  • Constructor Details

    • TrashPolicyDefault

      public TrashPolicyDefault()
  • Method Details

    • initialize

      @Deprecated public void initialize(Configuration conf, FileSystem fs, Path home)
      Deprecated.
      Description copied from class: TrashPolicy
      Used to setup the trash policy. Must be implemented by all TrashPolicy implementations.
      Specified by:
      initialize in class TrashPolicy
      Parameters:
      conf - the configuration to be used
      fs - the filesystem to be used
      home - the home directory
    • initialize

      public void initialize(Configuration conf, FileSystem fs)
      Description copied from class: TrashPolicy
      Used to setup the trash policy. Must be implemented by all TrashPolicy implementations. Different from initialize(conf, fs, home), this one does not assume trash always under /user/$USER due to HDFS encryption zone.
      Overrides:
      initialize in class TrashPolicy
      Parameters:
      conf - the configuration to be used
      fs - the filesystem to be used
    • isEnabled

      public boolean isEnabled()
      Description copied from class: TrashPolicy
      Returns whether the Trash Policy is enabled for this filesystem.
      Specified by:
      isEnabled in class TrashPolicy
      Returns:
      if isEnabled true,not false.
    • moveToTrash

      public boolean moveToTrash(Path path) throws IOException
      Description copied from class: TrashPolicy
      Move a file or directory to the current trash directory.
      Specified by:
      moveToTrash in class TrashPolicy
      Parameters:
      path - the path.
      Returns:
      false if the item is already in the trash or trash is disabled
      Throws:
      IOException - raised on errors performing I/O.
    • createCheckpoint

      public void createCheckpoint() throws IOException
      Description copied from class: TrashPolicy
      Create a trash checkpoint.
      Specified by:
      createCheckpoint in class TrashPolicy
      Throws:
      IOException - raised on errors performing I/O.
    • createCheckpoint

      public void createCheckpoint(Date date) throws IOException
      Throws:
      IOException
    • deleteCheckpoint

      public void deleteCheckpoint() throws IOException
      Description copied from class: TrashPolicy
      Delete old trash checkpoint(s).
      Specified by:
      deleteCheckpoint in class TrashPolicy
      Throws:
      IOException - raised on errors performing I/O.
    • deleteCheckpointsImmediately

      public void deleteCheckpointsImmediately() throws IOException
      Description copied from class: TrashPolicy
      Delete all checkpoints immediately, ie empty trash.
      Specified by:
      deleteCheckpointsImmediately in class TrashPolicy
      Throws:
      IOException - raised on errors performing I/O.
    • getCurrentTrashDir

      public Path getCurrentTrashDir()
      Description copied from class: TrashPolicy
      Get the current working directory of the Trash Policy This API does not work with files deleted from encryption zone when HDFS data encryption at rest feature is enabled as rename file between encryption zones or encryption zone and non-encryption zone is not allowed. The caller is recommend to use the new API TrashPolicy#getCurrentTrashDir(Path path). It returns the trash location correctly for the path specified no matter the path is in encryption zone or not.
      Specified by:
      getCurrentTrashDir in class TrashPolicy
      Returns:
      the path.
    • getCurrentTrashDir

      public Path getCurrentTrashDir(Path path) throws IOException
      Description copied from class: TrashPolicy
      Get the current trash directory for path specified based on the Trash Policy
      Overrides:
      getCurrentTrashDir in class TrashPolicy
      Parameters:
      path - path to be deleted
      Returns:
      current trash directory for the path to be deleted
      Throws:
      IOException - raised on errors performing I/O.
    • getEmptier

      public Runnable getEmptier() throws IOException
      Description copied from class: TrashPolicy
      Return a Runnable that periodically empties the trash of all users, intended to be run by the superuser.
      Specified by:
      getEmptier in class TrashPolicy
      Returns:
      Runnable.
      Throws:
      IOException - raised on errors performing I/O.