Sha256: 9ebe2d19687de3113c2eeca21f3e9bcf38a9ba2c27de15998a99fbf5328b8e16

Contents?: true

Size: 927 Bytes

Versions: 2

Compression:

Stored size: 927 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
        first_directory = File.join(base_path, parts[0])
        FileUtils.chmod permissions, first_directory
      end

      private

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

    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
imap-backup-0.0.5 lib/imap/backup/utils.rb
imap-backup-0.0.4 lib/imap/backup/utils.rb