<commit_before>require 'rexml/document'
require 'passenger/admin_tools'
require 'passenger/message_channel'

module Passenger
module AdminTools

class ControlProcess
	attr_accessor :path
	attr_accessor :pid
	
	def self.list
		results = []
		Dir["/tmp/passenger.*"].each do |dir|
			dir =~ /passenger.(\d+)\Z/
			next if !$1
			pid = $1.to_i
			begin
				results << ControlProcess.new(pid, dir)
			rescue ArgumentError
				# Do nothing.
			end
		end
		return results
	end
	<commit_msg>When listing control processes, clean up stale Passenger control process temp folders by default.<commit_after>require 'rexml/document'
require 'fileutils'
require 'passenger/admin_tools'
require 'passenger/message_channel'

module Passenger
module AdminTools

class ControlProcess
	attr_accessor :path
	attr_accessor :pid
	
	def self.list(clean_stale = true)
		results = []
		Dir["/tmp/passenger.*"].each do |dir|
			dir =~ /passenger.(\d+)\Z/
			next if !$1
			pid = $1.to_i
			begin
				results << ControlProcess.new(pid, dir)
			rescue ArgumentError
				# Stale Passenger temp folder. Clean it up if instructed.
				if clean_stale
					puts "*** Cleaning stale folder #{dir}"
					FileUtils.rm_rf(dir)
				end
			end
		end
		return results
	end
	
{'fraction_non_alphanumeric': 0.09967585089141005, 'fraction_numerical': 0.0032414910858995136, 'mean_word_length': 3.574074074074074, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6261527', 'n_tokens_mistral': 474, 'n_tokens_neox': 406, 'n_words': 116}