Module: ParallelReportPortal::FileUtils

Included in:
ParallelReportPortal
Defined in:
lib/parallel_report_portal/file_utils.rb

Overview

Common file handling methods

Instance Method Summary collapse

Instance Method Details

#delete_file(filename) ⇒ Object

Helper for deleting a file. It will not throw an exception if the file does not exist.

Parameters:

  • the (String)

    filename to delete



57
58
59
# File 'lib/parallel_report_portal/file_utils.rb', line 57

def delete_file(filename)
  File.delete(filename) if File.exist?(filename)
end

#file_open_exlock_and_block(filename, mode) {|file| ... } ⇒ Object

Open a file with an exclusive lock and yield the open file to the block. If the system is unable to access the file it will block until the lock is removed. This method guarantees that the lock will be removed.

Parameters:

  • filename (String)

    the name of the file to open

  • mode (String)

    the mode to open the file with (e.g. r, w+)

Yield Parameters:

  • file (File)

    the opened file



13
14
15
16
17
18
19
20
21
22
# File 'lib/parallel_report_portal/file_utils.rb', line 13

def file_open_exlock_and_block(filename, mode, &block)
  file = File.new(filename, mode)
  begin
    file.flock(File::LOCK_EX)
    yield(file) if block_given?
  ensure
    file.flock(File::LOCK_UN)
    file.close
  end
end

#hierarchy_filePathname

Returns a pathname for the hierarchy of this launch, initialising if necesssary.

Returns:

  • (Pathname)

    the hierarchy pathname



42
43
44
# File 'lib/parallel_report_portal/file_utils.rb', line 42

def hierarchy_file
  @hierarchy_file ||= Pathname(Dir.tmpdir) + ("report_portal_hierarchy_file_#{pid}.lck")
end

#launch_id_filePathname

Returns a pathname for the pid for this launch, initialising if necesssary.

Returns:

  • (Pathname)

    the pid pathname



35
36
37
# File 'lib/parallel_report_portal/file_utils.rb', line 35

def launch_id_file
  @lock_file ||= Pathname(Dir.tmpdir) + ("report_portal_tracking_file_#{pid}.lck")
end

#parallel?Boolean

Attempts to determin if the current environment is running under a parallel testing environment

Returns:

  • (Boolean)

    true if parallel



28
29
30
# File 'lib/parallel_report_portal/file_utils.rb', line 28

def parallel?
  !ENV['PARALLEL_PID_FILE'].nil?
end

#pidInteger

Gets the pid of this process or the parent pid if running in parallel mode.

Returns:

  • (Integer)

    the pid



49
50
51
# File 'lib/parallel_report_portal/file_utils.rb', line 49

def pid
  pid = parallel? ? Process.ppid : Process.pid
end