Sha256: d3f9b14d36d9855c53cc2721f8c756c9317960f121c5063c335bcf701d99ca53

Contents?: true

Size: 1.1 KB

Versions: 3

Compression:

Stored size: 1.1 KB

Contents

# Migrate trash to correct directory on Linux due to a configuration bug in previous releases.
#
# It used to be that the default trash path was the same on every platform, so everything used to go to `~/.Trash`
# regardless of OS.  (For what it's worth, that used to be the correct trash path on older releases of Ubuntu.)
module Maid
  module TrashMigration
    class << self
      def incorrect_trash
        File.expand_path('~/.Trash') + '/'
      end

      def correct_trash
        Maid.new.trash_path
      end

      def needed?
        Platform.linux? &&
          File.directory?(incorrect_trash) &&
          !ENV['MAID_NO_MIGRATE_TRASH']
      end

      def perform
        maid = ::Maid::Maid.new(trash_path: correct_trash)
        # Use local variable so it's available in the closure used by `instance_eval`
        path = incorrect_trash

        # Might as well use Maid itself for this :)
        maid.instance_eval do
          rule 'Migrate Linux trash to correct path' do
            trash(dir("#{path}/*"))
            trash(path)
          end
        end

        maid.clean
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
maid-0.10.0 lib/maid/trash_migration.rb
maid-0.10.0.pre.alpha.3 lib/maid/trash_migration.rb
maid-0.10.0.pre.alpha.2 lib/maid/trash_migration.rb