module Repo::SVN
Repo::SVN
is a connector for svnserve @author Bryan T. Meyers
Public Class Methods
Create a single file @param [String] conf the repo config @param [String] repo the new repo name @param [String] id the relative path to the file @param [String] content the updated file @param [String] message the commit message @param [String] mime the mime-type to set @param [String] username the Author of this change @return [Integer] status code
# File lib/app/repo/svn.rb, line 197 def self.do_create_file(conf, repo, id, content, message, mime, username) do_update_file(conf, repo, id, content, message, mime, username) end
Read a single file @param [String] conf the repo config @param [String] repo the new repo name @param [String] id the relative path to the file @param [String] rev the revision number to access @return [String] the file
# File lib/app/repo/svn.rb, line 36 def self.do_read_file(conf, repo, id, rev) options = "--username #{conf['user']} --password #{conf['password']}" if rev.nil? rev = 'HEAD' end if conf['web_folder'].nil? body = `svn cat #{options} -r #{rev} '#{conf['protocol']}://#{conf['host']}/#{repo}/#{id}'` else body = `svn cat #{options} -r #{rev} '#{conf['protocol']}://#{conf['host']}/#{repo}/#{conf['web_folder']}/#{id}'` end if $?.success? body else 500 end end
Read Metadata for a single file @param [String] conf the repo config @param [String] repo the new repo name @param [String] id the relative path to the file @param [String] rev the revision number to access @return [Hash] the metadata
# File lib/app/repo/svn.rb, line 87 def self.do_read_info(conf, repo, id, rev) options = "--username #{conf['user']} --password #{conf['password']}" if rev.nil? rev = 'HEAD' end if conf['web_folder'].nil? info = `svn info #{options} -r #{rev} --xml '#{conf['protocol']}://#{conf['host']}/#{repo}/#{id}'` else info = `svn info #{options} -r #{rev} --xml '#{conf['protocol']}://#{conf['host']}/#{repo}/#{conf['web_folder']}/#{id}'` end unless $?.exitstatus == 0 return 404 end info = @@nori.parse(info) info[:info][:entry] end
Read a directory listing @param [String] conf the repo config @param [String] repo the repo name @param [String] id the relative path to the file @return [Array] the directory listing
# File lib/app/repo/svn.rb, line 59 def self.do_read_listing(conf, repo, id = nil) options = "--username #{conf['user']} --password #{conf['password']}" if conf['web_folder'].nil? if id.nil? list = `svn list #{options} --xml '#{conf['protocol']}://#{conf['host']}/#{repo}'` else list = `svn list #{options} --xml '#{conf['protocol']}://#{conf['host']}/#{repo}/#{id}'` end else if id.nil? list = `svn list #{options} --xml '#{conf['protocol']}://#{conf['host']}/#{repo}/#{conf['web_folder']}'` else list = `svn list #{options} --xml '#{conf['protocol']}://#{conf['host']}/#{repo}/#{conf['web_folder']}/#{id}'` end end unless $?.exitstatus == 0 return 404 end list = @@nori.parse(list) list[:lists][:list][:entry] end
Get a file's MIME type @param [String] conf the repo config @param [String] repo the new repo name @param [String] id the relative path to the file @param [String] rev the revision number to access @return [String] the MIME type
# File lib/app/repo/svn.rb, line 111 def self.do_read_mime(conf, repo, id, rev) options = "--username #{conf['user']} --password #{conf['password']}" if rev.nil? rev = 'HEAD' end if conf['web_folder'].nil? mime = `svn propget #{options} -r #{rev} --xml svn:mime-type '#{conf['protocol']}://#{conf['host']}/#{repo}/#{id}'` else mime = `svn propget #{options} -r #{rev} --xml svn:mime-type '#{conf['protocol']}://#{conf['host']}/#{repo}/#{conf['web_folder']}/#{id}'` end unless $?.success? return 500 end mime = @@nori.parse(mime) if mime[:properties].nil? 'application/octet-stream' else mime[:properties][:target][:property] end end
Update or create a single file @param [String] conf the repo config @param [String] repo the new repo name @param [String] id the relative path to the file @param [String] content the updated file @param [String] message the commit message @param [String] mime the mime-type to set @param [String] username the Author of this change @return [Integer] status code
# File lib/app/repo/svn.rb, line 141 def self.do_update_file(conf, repo, id, content, message, mime, username) options = "--username #{conf['user']} --password #{conf['password']}" status = 500 repo_path = "/tmp/#{username}/#{repo}" unless Dir.exist? repo_path FileUtils.mkdir_p(repo_path) end `svn checkout --depth empty #{options} '#{conf['protocol']}://#{conf['host']}/#{repo}' '#{repo_path}'` if $?.exitstatus == 0 Dir.chdir(repo_path) do file_path = CGI.unescape(id) if conf['web_folder'] file_path = "#{conf['web_folder']}/#{file_path}" end folder_path = file_path.split('/') folder_path.pop folder_path = folder_path.join('/') `svn update --parents #{options} '#{file_path}'` unless Dir.exist? folder_path FileUtils.mkdir_p(folder_path) end file = File.open(file_path, 'w') file.syswrite(content) file.close `svn add --force *` $stderr.puts `svn status` `svn propset svn:mime-type '#{mime ? mime : 'application/octet-stream'}' '#{file_path}'` if $?.exitstatus != 0 break end `svn commit #{options} -m "#{message}"` if $?.exitstatus != 0 break end `svn propset #{options} --revprop -r HEAD svn:author '#{username}'` end end `rm -R '#{repo_path}'` if $?.exitstatus == 0 status = 200 end status end