Class: Imap::Backup::Serializer::Directory

Inherits:
Object
  • Object
show all
Defined in:
lib/imap/backup/serializer/directory.rb

Overview

Ensures that serialization directories exist and have the correct permissions.

Constant Summary collapse

DIRECTORY_PERMISSIONS =

The desired permissions for all directories that store backups

0o700

Instance Method Summary collapse

Constructor Details

#initialize(path, relative) ⇒ void

Parameters:

  • path (String)

    The base path of the account backup

  • relative (String)

    The path relative from the base



20
21
22
23
# File 'lib/imap/backup/serializer/directory.rb', line 20

def initialize(path, relative)
  @path = path
  @relative = relative
end

Instance Method Details

#ensure_existsvoid

This method returns an undefined value.

Creates the directory, if present and sets it’s access permissions



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/imap/backup/serializer/directory.rb', line 28

def ensure_exists
  if !File.directory?(full_path)
    Serializer::FolderMaker.new(
      base: path, path: relative, permissions: DIRECTORY_PERMISSIONS
    ).run
  end

  return if OS.windows?
  return if FileMode.new(filename: full_path).mode == DIRECTORY_PERMISSIONS

  FileUtils.chmod DIRECTORY_PERMISSIONS, full_path
end