try to limit file name lengths to the maximum possible length

This commit is contained in:
Ward Wouts 2002-07-30 21:55:08 +00:00
parent 4cfb48677d
commit c3e5c8bf30

View file

@ -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