TrashPolicyDefault (Apache Hadoop Common 3.5.0 API)
Description: declaration: package: org.apache.hadoop.fs, class: TrashPolicyDefault

Package org.apache.hadoop.fs

# Class TrashPolicyDefault

java.lang.Object
org.apache.hadoop.conf.Configured
org.apache.hadoop.fs.TrashPolicy
org.apache.hadoop.fs.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.)

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `protected class`
  `TrashPolicyDefault.Emptier`

- ## Field Summary

  ### Fields inherited from class org.apache.hadoop.fs.TrashPolicy

  `deletionInterval, fs, trash`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `TrashPolicyDefault()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `createCheckpoint()`
  Create a trash checkpoint.
  `void`
  `createCheckpoint(Date date)`
  `void`
  `deleteCheckpoint()`
  Delete old trash checkpoint(s).
  `void`
  `deleteCheckpointsImmediately()`
  Delete all checkpoints immediately, ie empty trash.
  `Path`
  `getCurrentTrashDir()`
  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.
  `Path`
  `getCurrentTrashDir(Path path)`
  Get the current trash directory for path specified based on the Trash Policy
  `Runnable`
  `getEmptier()`
  Return a `Runnable` that periodically empties the trash of all users, intended to be run by the superuser.
  `void`
  `initialize(Configuration conf, FileSystem fs)`
  Used to setup the trash policy.
  `void`
  `initialize(Configuration conf, FileSystem fs, Path home)`
  Deprecated.
  Use `initialize(Configuration, FileSystem)` instead.
  `boolean`
  `isEnabled()`
  Returns whether the Trash Policy is enabled for this filesystem.
  `boolean`
  `moveToTrash(Path path)`
  Move a file or directory to the current trash directory.

  ### Methods inherited from class org.apache.hadoop.fs.TrashPolicy

  `getInstance, getInstance`

  ### Methods inherited from class org.apache.hadoop.conf.Configured

  `getConf, setConf`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### TrashPolicyDefault

    public TrashPolicyDefault()

- ## Method Details

  - ### initialize

    @Deprecated public void initialize(Configuration conf, FileSystem fs, Path home)
    Deprecated.
    Use `initialize(Configuration, FileSystem)` instead.
    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.