Path: blob/trunk/rb/lib/selenium/webdriver/common/file_reaper.rb
1865 views
# frozen_string_literal: true12# Licensed to the Software Freedom Conservancy (SFC) under one3# or more contributor license agreements. See the NOTICE file4# distributed with this work for additional information5# regarding copyright ownership. The SFC licenses this file6# to you under the Apache License, Version 2.0 (the7# "License"); you may not use this file except in compliance8# with the License. You may obtain a copy of the License at9#10# http://www.apache.org/licenses/LICENSE-2.011#12# Unless required by applicable law or agreed to in writing,13# software distributed under the License is distributed on an14# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY15# KIND, either express or implied. See the License for the16# specific language governing permissions and limitations17# under the License.1819module Selenium20module WebDriver21#22# @api private23#2425module FileReaper26class << self27attr_writer :reap2829def reap?30@reap = defined?(@reap) ? @reap : true31end3233def tmp_files34@tmp_files ||= Hash.new { |hash, pid| hash[pid] = [] }35@tmp_files[Process.pid]36end3738def <<(file)39tmp_files << file40end4142def reap(file)43return unless reap?4445raise Error::WebDriverError, "file not added for reaping: #{file.inspect}" unless tmp_files.include?(file)4647FileUtils.rm_rf tmp_files.delete(file)48end4950def reap!51if reap?52tmp_files.each { |file| FileUtils.rm_rf(file) }53true54else55false56end57end58end5960# we *do* want child process reaping, so not using Platform.exit_hook here.61at_exit { reap! }62end # FileReaper63end # WebDriver64end # Selenium656667