Sha256: 27f86569d3fc1e8b554ace66be39aa377afb512e0ab820fc8ce62194b027a8c4

Contents?: true

Size: 961 Bytes

Versions: 4

Compression:

Stored size: 961 Bytes

Contents

# encoding: utf-8
require 'fileutils'

module Imap
  module Backup
    module Utils
      def self.check_permissions(filename, limit)
        actual = stat(filename)
        mask   = ~limit & 0777
        if actual & mask != 0
          raise "Permissions on '#{filename}' should be #{oct(limit)}, not #{oct(actual)}" 
        end
      end

      def self.stat(filename)
        return nil unless File.exist?(filename)

        stat = File.stat(filename)
        stat.mode & 0777
      end

      def self.make_folder(base_path, path, permissions)
        parts = path.split('/')
        return if parts.size == 0
        full_path = File.join(base_path, path)
        FileUtils.mkdir_p full_path
        path = base_path
        parts.each do |part|
          path = File.join(path, part)
          FileUtils.chmod permissions, path
        end
      end

      private

      def self.oct(permissions)
        "0%o" % permissions
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
imap-backup-1.0.9 lib/imap/backup/utils.rb
imap-backup-1.0.8 lib/imap/backup/utils.rb
imap-backup-1.0.7 lib/imap/backup/utils.rb
imap-backup-1.0.6 lib/imap/backup/utils.rb