Look for gitweb in /usr/share/gitweb
Debian based systems seem to install the gitweb CSS and logo into /usr/share/gitweb. So look for these files before the older /var/www assumption when using the system supplied CGI. Bug: issue 494 Change-Id: I03d470b3be095aaaa98ebf7ef66d5b29e712eb73 Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
@@ -34,6 +34,17 @@ by Gerrit Code Review. Site specific overrides can be placed in
|
||||
`'$site_path'/etc/gitweb_config.perl`, as this file is loaded as
|
||||
part of the generated configuration file.
|
||||
|
||||
Logo and CSS
|
||||
~~~~~~~~~~~~
|
||||
|
||||
If the package-manager installed CGI (`/usr/lib/cgi-bin/gitweb.cgi`)
|
||||
is being used, the stock CSS and logo files will be served from
|
||||
either `/usr/share/gitweb` or `/var/www`.
|
||||
|
||||
Otherwise, Gerrit expects `gitweb.css` and `git-logo.png` to be found
|
||||
in the same directory as the CGI script itself. This matches with
|
||||
the default source code distribution, and most custom installations.
|
||||
|
||||
Access Control
|
||||
~~~~~~~~~~~~~~
|
||||
|
||||
|
||||
@@ -78,7 +78,10 @@ public class GitWebConfig {
|
||||
return;
|
||||
}
|
||||
|
||||
File cgi, css, logo;
|
||||
final File pkgCgi = new File("/usr/lib/cgi-bin/gitweb.cgi");
|
||||
String[] resourcePaths = {"/usr/share/gitweb", "/var/www"};
|
||||
File cgi;
|
||||
|
||||
if (cfgCgi != null) {
|
||||
// Use the CGI script configured by the administrator, failing if it
|
||||
// cannot be used as specified.
|
||||
@@ -91,27 +94,32 @@ public class GitWebConfig {
|
||||
throw new IllegalStateException("Cannot execute gitweb.cgi: " + cgi);
|
||||
}
|
||||
|
||||
// Assume the administrator pointed us the distribution, which
|
||||
// also has the corresponding CSS and logo file.
|
||||
if (!cgi.equals(pkgCgi)) {
|
||||
// Assume the administrator pointed us to the distribution,
|
||||
// which also has the corresponding CSS and logo file.
|
||||
//
|
||||
resourcePaths = new String[] {cgi.getParentFile().getAbsolutePath()};
|
||||
}
|
||||
|
||||
} else if (pkgCgi.isFile() && pkgCgi.canExecute()) {
|
||||
// Use the OS packaged CGI.
|
||||
//
|
||||
css = new File(cgi.getParentFile(), "gitweb.css");
|
||||
logo = new File(cgi.getParentFile(), "git-logo.png");
|
||||
log.debug("Assuming gitweb at " + pkgCgi);
|
||||
cgi = pkgCgi;
|
||||
|
||||
} else {
|
||||
// Try to use the OS packaged CGI.
|
||||
//
|
||||
final File s = new File("/usr/lib/cgi-bin/gitweb.cgi");
|
||||
if (s.isFile()) {
|
||||
log.debug("Assuming gitweb at " + s);
|
||||
cgi = s;
|
||||
css = new File("/var/www/gitweb.css");
|
||||
logo = new File("/var/www/git-logo.png");
|
||||
log.warn("gitweb not installed (no " + pkgCgi + " found)");
|
||||
cgi = null;
|
||||
resourcePaths = new String[] {};
|
||||
}
|
||||
|
||||
} else {
|
||||
log.warn("gitweb not installed (no " + s + " found)");
|
||||
cgi = null;
|
||||
css = null;
|
||||
logo = null;
|
||||
File css = null, logo = null;
|
||||
for (String path : resourcePaths) {
|
||||
File dir = new File(path);
|
||||
css = new File(dir, "gitweb.css");
|
||||
logo = new File(dir, "git-logo.png");
|
||||
if (css.isFile() && logo.isFile()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -51,9 +51,13 @@ class GitLogoServlet extends HttpServlet {
|
||||
@Inject
|
||||
GitLogoServlet(final GitWebConfig gitWebConfig) throws IOException {
|
||||
byte[] png;
|
||||
try {
|
||||
png = IO.readFully(gitWebConfig.getGitLogoPNG());
|
||||
} catch (FileNotFoundException e) {
|
||||
if (gitWebConfig.getGitLogoPNG() != null) {
|
||||
try {
|
||||
png = IO.readFully(gitWebConfig.getGitLogoPNG());
|
||||
} catch (FileNotFoundException e) {
|
||||
png = null;
|
||||
}
|
||||
} else {
|
||||
png = null;
|
||||
}
|
||||
raw = png;
|
||||
|
||||
@@ -70,12 +70,17 @@ abstract class GitWebCssServlet extends HttpServlet {
|
||||
|
||||
GitWebCssServlet(final File src, final GitWebConfig gitWebConfig)
|
||||
throws IOException {
|
||||
final File dir = src.getParentFile();
|
||||
final String name = src.getName();
|
||||
final String raw = HtmlDomUtil.readFile(dir, name);
|
||||
if (raw != null) {
|
||||
raw_css = raw.getBytes(ENC);
|
||||
gz_css = HtmlDomUtil.compress(raw_css);
|
||||
if (src != null) {
|
||||
final File dir = src.getParentFile();
|
||||
final String name = src.getName();
|
||||
final String raw = HtmlDomUtil.readFile(dir, name);
|
||||
if (raw != null) {
|
||||
raw_css = raw.getBytes(ENC);
|
||||
gz_css = HtmlDomUtil.compress(raw_css);
|
||||
} else {
|
||||
raw_css = null;
|
||||
gz_css = null;
|
||||
}
|
||||
} else {
|
||||
raw_css = null;
|
||||
gz_css = null;
|
||||
|
||||
Reference in New Issue
Block a user