Enum Class MoveFlags

java.lang.Object
java.lang.Enum<MoveFlags>
com.frostwire.jlibtorrent.MoveFlags
All Implemented Interfaces:
Serializable, Comparable<MoveFlags>, Constable

public enum MoveFlags extends Enum<MoveFlags>
Flags controlling storage move behavior for torrent files.

MoveFlags specifies how the BitTorrent session should handle file conflicts when moving a torrent's downloaded data to a new location on disk. This is useful for disk space management, organizing downloads, or migrating between storage devices.

Understanding Storage Move Operations:
Moving torrent storage involves copying or moving files from current location to a new directory. These flags control what happens if files already exist at the destination:

  • ALWAYS_REPLACE_FILES: Overwrite any existing destination files
  • FAIL_IF_EXIST: Abort operation if destination files exist (safest)
  • DONT_REPLACE: Use existing destination files instead of copying

Moving Torrent Storage:

 // Get handle to active torrent
 TorrentHandle th = sm.find(infoHash);

 // Move downloads to new location
 String newPath = \"/mnt/faster_disk/downloads\";
 th.moveStorage(newPath, MoveFlags.ALWAYS_REPLACE_FILES);

 // Operation is asynchronous; listen for completion
 sm.addListener(new AlertListener() {
     public int[] types() {
         return new int[] {AlertType.STORAGE_MOVED.swig()};
     }

     public void alert(Alert<?> alert) {
         StorageMovedAlert sma = (StorageMovedAlert) alert;
         System.out.println(\"Storage moved to: \" + sma.path());
     }
 });
 

MoveFlags Comparison:

Storage Move Flag Behavior
FlagBehaviorUse CaseSafety
ALWAYS_REPLACE_FILES Overwrites existing destination files Cleanup/reorganization, trusted destinations Medium - deletes existing data
FAIL_IF_EXIST Aborts if destination files exist Automated operations, safety-critical High - preserves existing files
DONT_REPLACE Uses existing destination files Resume after crash, keep newer versions Medium - assumes destination is correct

Real-World Scenarios:

 // Scenario 1: Disk full - move to larger drive
 // Use ALWAYS_REPLACE_FILES (trusted new location)
 String newDisk = \"/media/external/torrents\";
 th.moveStorage(newDisk, MoveFlags.ALWAYS_REPLACE_FILES);

 // Scenario 2: Automated organization system
 // Use FAIL_IF_EXIST (safety check, abort on conflicts)
 String organized = \"/data/organized/\" + category;
 th.moveStorage(organized, MoveFlags.FAIL_IF_EXIST);

 // Scenario 3: Restart after crash
 // Use DONT_REPLACE (keep partially downloaded files)
 String resumed = \"/downloads/resumed\";
 th.moveStorage(resumed, MoveFlags.DONT_REPLACE);
 

Move Completion Detection:

 // Listen for move operations
 sm.addListener(new AlertListener() {
     public int[] types() {
         return new int[] {
             AlertType.STORAGE_MOVED.swig(),
             AlertType.STORAGE_MOVED_FAILED.swig()
         };
     }

     public void alert(Alert<?> alert) {
         if (alert.type() == AlertType.STORAGE_MOVED) {
             StorageMovedAlert sma = (StorageMovedAlert) alert;
             System.out.println(\"✓ Moved to: \" + sma.path());
         } else {
             StorageMovedFailedAlert smfa = (StorageMovedFailedAlert) alert;
             System.out.println(\"✗ Move failed: \" + smfa.message());
         }
     }
 });
 

Important Notes:

  • Move operation is asynchronous; check STORAGE_MOVED alert for completion
  • Destination directory should exist before move
  • Current downloads continue during move operation
  • Operation may fail if insufficient disk space
  • Use FAIL_IF_EXIST for programmatic safety
See Also:
  • Enum Constant Details

    • ALWAYS_REPLACE_FILES

      public static final MoveFlags ALWAYS_REPLACE_FILES
      Replace any files in the destination when copying or moving the storage.
    • FAIL_IF_EXIST

      public static final MoveFlags FAIL_IF_EXIST
      If any files that we want to copy exist in the destination, fail the whole operation and don't perform any copy or move. There is an inherent race condition in this mode. The files are checked for existence before the operation starts. In between the check and performing the copy, the destination files may be created, in which case they are replaced.
    • DONT_REPLACE

      public static final MoveFlags DONT_REPLACE
      If any files exist in the target, take those files instead of the ones we may have in the source.
  • Method Details

    • values

      public static MoveFlags[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static MoveFlags valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null
    • swig

      public com.frostwire.jlibtorrent.swig.move_flags_t swig()
      Returns:
      the native value
    • fromSwig

      public static MoveFlags fromSwig(com.frostwire.jlibtorrent.swig.move_flags_t swigValue)
      Parameters:
      swigValue - the native value