org.apache.hadoop.fs

## Class Trash

- java.lang.Object
- - org.apache.hadoop.conf.Configured
  - - org.apache.hadoop.fs.Trash

- All Implemented Interfaces:
    Configurable

      @InterfaceAudience.Public
       @InterfaceStability.Stable
      public class Trash
      extends Configured

  Provides a trash facility which supports pluggable Trash policies. See the implementation of the configured TrashPolicy for more details.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `Trash(Configuration conf)` Construct a trash can accessor.
    `Trash(FileSystem fs, Configuration conf)` Construct a trash can accessor for the FileSystem provided.

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `checkpoint()` Create a trash checkpoint.
    `void` | `expunge()` Delete old checkpoint(s).
    `void` | `expungeImmediately()` Delete all trash immediately.
    `Path` | `getCurrentTrashDir(Path path)`
    `Runnable` | `getEmptier()` Return a `Runnable` that periodically empties the trash of all users, intended to be run by the superuser.
    `boolean` | `isEnabled()` Returns whether the trash is enabled for this filesystem
    `static boolean` | `moveToAppropriateTrash(FileSystem fs, Path p, Configuration conf)` In case of the symlinks or mount points, one has to move the appropriate trashbin in the actual volume of the path p being deleted.
    `boolean` | `moveToTrash(Path path)` Move a file or directory to the current trash directory.

    - ### 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 Detail

    - #### Trash

          public Trash(Configuration conf)
                throws IOException

      Construct a trash can accessor.
      Parameters:
        `conf` - a Configuration
      Throws:
        `IOException`

    - #### Trash

          public Trash(FileSystem fs,
                       Configuration conf)
                throws IOException

      Construct a trash can accessor for the FileSystem provided.
      Parameters:
        `fs` - the FileSystem
        `conf` - a Configuration
      Throws:
        `IOException`

  - ### Method Detail

    - #### moveToAppropriateTrash

          public static boolean moveToAppropriateTrash(FileSystem fs,
                                                       Path p,
                                                       Configuration conf)
                                                throws IOException

      In case of the symlinks or mount points, one has to move the appropriate trashbin in the actual volume of the path p being deleted. Hence we get the file system of the fully-qualified resolved-path and then move the path p to the trashbin in that volume,
      Parameters:
        `fs` - - the filesystem of path p
        `p` - - the path being deleted - to be moved to trasg
        `conf` - - configuration
      Returns:
        false if the item is already in the trash or trash is disabled
      Throws:
        `IOException` - on error

    - #### isEnabled

          public boolean isEnabled()

      Returns whether the trash is enabled for this filesystem

    - #### moveToTrash

          public boolean moveToTrash(Path path)
                              throws IOException

      Move a file or directory to the current trash directory.
      Returns:
        false if the item is already in the trash or trash is disabled
      Throws:
        `IOException`

    - #### checkpoint

          public void checkpoint()
                          throws IOException

      Create a trash checkpoint.
      Throws:
        `IOException`

    - #### expunge

          public void expunge()
                       throws IOException

      Delete old checkpoint(s).
      Throws:
        `IOException`

    - #### expungeImmediately

          public void expungeImmediately()
                                  throws IOException

      Delete all trash immediately.
      Throws:
        `IOException`

    - #### getEmptier

          public Runnable getEmptier()
                              throws IOException

      Return a `Runnable` that periodically empties the trash of all users, intended to be run by the superuser.
      Throws:
        `IOException`

    - #### getCurrentTrashDir

          public Path getCurrentTrashDir(Path path)
                                  throws IOException

      Throws:
        `IOException`

Copyright © 2022 Apache Software Foundation. All rights reserved.