From c3e5c8bf309a1518f08f1899f3b19cf8d6aef6c8 Mon Sep 17 00:00:00 2001 From: Ward Wouts Date: Tue, 30 Jul 2002 21:55:08 +0000 Subject: [PATCH] try to limit file name lengths to the maximum possible length --- trunk/ripnews/ripnews.rb | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/trunk/ripnews/ripnews.rb b/trunk/ripnews/ripnews.rb index 878074f..0672f57 100755 --- a/trunk/ripnews/ripnews.rb +++ b/trunk/ripnews/ripnews.rb @@ -262,12 +262,29 @@ def output_data(subject, mode, filename="", body="") if @config[group].has_key?("-L") and @config[group]["-L"] print "longname\n" if Debuglevel > 1 outfile = subject + while outfile.length > @maxfilelength + outfile = outfile[0...-1] + end elsif @config[group].has_key?("-C") and @config[group]["-C"] print "combinedname\n" if Debuglevel > 1 outfile = "#{subject} [#{filename}]" + while outfile > @maxfilelength + lastlength = outfile.length + subject = subject[0...-1] + outfile = "#{subject} [#{filename}]" # this is going to loop if the #{filename} is too long :( + if outfile.length == lastlength + outfile = filename + while outfile > @maxfilelength + outfile = outfile[0...-1] + end + end + end else print "shortname\n" if Debuglevel > 1 outfile = filename + while outfile > @maxfilelength + outfile = outfile[0...-1] + end end if save_file("#{@config[group]["DATADIR"]}/#{group}", outfile, body) @articles.group_update_newsrc(subject) @@ -287,6 +304,22 @@ def check_ext(filename, mode) end end +def get_max_file_length(tempdir=".") +i = 500 +name = "a"*i +begin + file = File.new("#{tempdir}/#{name}", "w", "0644").close + File.delete(name) +rescue Errno::ENAMETOOLONG + i -= 1 + name = "a"*i + retry +end + i -= 14 # this is how many characters are still likely to be appended + # is the filename already exists '-<#{date}.#{count}>' in save_file + return i +end + ############################################################################################# $stdout.sync=true # line buffered output @@ -295,6 +328,9 @@ defaults = parse_options(defaults) parse_config(defaults) check_config +@maxfilelength = get_max_file_length(@config[@config.key[0]]["TEMPDIR"]) +print "MAXFILELENGTH: #{@maxfilelength}\n" + print "$Id$\n" if Debuglevel > 2