[Pkg-ocaml-maint-commits] r1325 - in trunk/projects/approx: . debian

Eric Cooper ecc-guest@costa.debian.org
Thu, 28 Apr 2005 00:28:12 +0000


Author: ecc-guest
Date: 2005-04-28 00:28:11 +0000 (Thu, 28 Apr 2005)
New Revision: 1325

Added:
   trunk/projects/approx/debian/NEWS
Modified:
   trunk/projects/approx/approx.conf
   trunk/projects/approx/approx.conf.5
   trunk/projects/approx/approx.ml
   trunk/projects/approx/debian/approx.postinst
   trunk/projects/approx/debian/approx.postrm
   trunk/projects/approx/debian/changelog
   trunk/projects/approx/default_config.ml
   trunk/projects/approx/default_config.mli
   trunk/projects/approx/gc_approx.ml
Log:
make sure /var/cache/approx exists before trying to chown it (closes: #306621)

no longer allow the cache directory to be specified in approx.conf;
always use /var/cache/approx (which can be a symlink)


Modified: trunk/projects/approx/approx.conf
===================================================================
--- trunk/projects/approx/approx.conf	2005-04-27 22:39:34 UTC (rev 1324)
+++ trunk/projects/approx/approx.conf	2005-04-28 00:28:11 UTC (rev 1325)
@@ -2,7 +2,6 @@
 # to uncomment them unless you want a different value.
 
 #port		9999
-#cache		/var/cache/approx
 #interval	720
 #debug		false
 

Modified: trunk/projects/approx/approx.conf.5
===================================================================
--- trunk/projects/approx/approx.conf.5	2005-04-27 22:39:34 UTC (rev 1324)
+++ trunk/projects/approx/approx.conf.5	2005-04-28 00:28:11 UTC (rev 1325)
@@ -23,10 +23,6 @@
 Specifies the TCP port on which the
 .BR approx (8)
 server listens for HTTP requests (default: 9999)
-.IP cache
-Specifies the directory used to cache downloaded Debian archive files
-(default:
-.IR /var/cache/approx )
 .IP interval
 Specifies the time in minutes after which a cached file will be
 considered too old to deliver without first checking with the remote

Modified: trunk/projects/approx/approx.ml
===================================================================
--- trunk/projects/approx/approx.ml	2005-04-27 22:39:34 UTC (rev 1324)
+++ trunk/projects/approx/approx.ml	2005-04-28 00:28:11 UTC (rev 1325)
@@ -13,6 +13,20 @@
 
 let message fmt = kprintf (Syslog.syslog log `LOG_INFO) fmt
 
+let error_message = function
+  | Unix.Unix_error (err, str, arg) ->
+      if err = Unix.EADDRINUSE && str = "bind" then
+	begin
+	  message "Port %d is already in use" port;
+	  if port = 9999 then message "Perhaps apt-proxy is already running?"
+	end
+      else
+	message "%s: %s%s"
+	  str (Unix.error_message err)
+	  (if arg = "" then "" else sprintf " (%s)" arg)
+  | e ->
+      message "%s" (Printexc.to_string e)
+
 let print_config () =
   let units u = function
     | 0 -> ""
@@ -21,7 +35,7 @@
   in
   message "Config file: %s" config_file;
   message "Port: %d" port;
-  message "Cache: %s" cache;
+  message "Cache: %s" cache_dir;
   message "Interval:%s%s"
     (units "hour" (interval / 60)) (units "minute" (interval mod 60));
   message "Debug: %B" debug
@@ -145,7 +159,8 @@
     cache_chan := Some (create_file (name ^ ".tmp"));
     cache_file := name
   with e ->
-    message "Cannot cache %s (reason: %s)" name (Printexc.to_string e)
+    error_message e;
+    message "Cannot cache %s" name
 
 let write_cache str =
   match !cache_chan with
@@ -299,7 +314,7 @@
     handler url local_name ims chan
   with e ->
     remove_cache ();
-    message "%s" (Printexc.to_string e);
+    error_message e;
     respond_not_found ~url: path chan
 
 let serve_file path headers chan =
@@ -326,17 +341,11 @@
   ignore (Unix.setsid ());
   List.iter Unix.close [Unix.stdin; Unix.stdout; Unix.stderr];
   try
-    Unix.chdir cache;
+    Unix.chdir cache_dir;
     print_config ();
     main (daemon_spec ~port ~callback ~mode: `Single ~timeout: None ())
-  with
-  | Unix.Unix_error (Unix.EADDRINUSE, "bind", _) ->
-      message "Port %d is already in use" port;
-      if port = 9999 then message "Perhaps apt-proxy is already running?"
-  | Unix.Unix_error (err, str, _) ->
-      message "%s: %s" str (Unix.error_message err);
-  | e ->
-      message "%s" (Printexc.to_string e)
+  with e ->
+    error_message e
 
 let () =
   (* double fork to detach daemon *)

Added: trunk/projects/approx/debian/NEWS
===================================================================
--- trunk/projects/approx/debian/NEWS	2005-04-27 22:39:34 UTC (rev 1324)
+++ trunk/projects/approx/debian/NEWS	2005-04-28 00:28:11 UTC (rev 1325)
@@ -0,0 +1,8 @@
+approx (1.13) unstable; urgency=low
+
+The approx daemon always uses /var/cache/approx now;
+the cache directory can no longer be changed in the approx.conf file.
+But /var/cache/approx can be a symbolic link, so the cache directory
+can still be located elsewhere.
+
+ -- Eric Cooper <ecc@cmu.edu>  Wed, 27 Apr 2005 18:39:13 -0400

Modified: trunk/projects/approx/debian/approx.postinst
===================================================================
--- trunk/projects/approx/debian/approx.postinst	2005-04-27 22:39:34 UTC (rev 1324)
+++ trunk/projects/approx/debian/approx.postinst	2005-04-28 00:28:11 UTC (rev 1325)
@@ -7,30 +7,45 @@
     exit 0
 fi
 
+# print the value set for the key ($1) or the specified default ($2) if not set
+# warning: don't insert any whitespace between the double and single quotes!
+
+approx_config() {
+    key="$1"
+    default="$2"
+    awk 'BEGIN { found = 0 } $1 == "'$key'" { found = 1; print $2; exit } END { if (!found) print "'$default'" }' /etc/approx/approx.conf
+}
+
 # add the approx user
 if ! getent passwd approx >/dev/null; then
     adduser --quiet --system --group --no-create-home --home /var/cache/approx approx
 fi
 
-# make sure cache is owned by the approx user
-if dpkg --compare-versions "$oldversion" lt 1.12; then
-    chown -R approx:approx /var/cache/approx
+# make sure the cache is owned by the approx user
+if dpkg --compare-versions "$oldversion" lt 1.12 && [ -d /var/cache/approx ]; then
+    chown -R approx:approx /var/cache/approx/.
 fi
 
+# check for non-standard cache location
+cache=$(approx_config cache /var/cache/approx)
+if dpkg --compare-versions "$oldversion" lt 1.13 && [ "$cache" != /var/cache/approx ]; then
+    cat >&2 <<EOF
+Warning: the location of the cache can no longer be set in approx.conf
+         (you appear to have it set to $cache).
+	 See /usr/share/doc/approx/NEWS.Debian.gz for details.
+EOF
+fi
+
 # check for potential conflict with apt-proxy
-if [ -x /etc/init.d/apt-proxy ]; then
-    default_approx_port=9999
-    approx_port=$(awk '/^[ \t]*port/{print $2}' /etc/approx/approx.conf) || true
-    if [ -z "$approx_port" ]; then
-	approx_port=$default_approx_port;
-    fi
-    if [ "$approx_port" = "$default_approx_port" ]; then
-	echo "Warning: apt-proxy appears to be installed also." >&2
-	echo "         For compatibility with client sources.list files," >&2
-	echo "         approx uses the same port (9999) by default." >&2
-	echo "         Please stop or remove apt-proxy, or configure" >&2
-	echo "         one of them to listen on a different port." >&2
-    fi
+port=$(approx_config port 9999)
+if [ -x /etc/init.d/apt-proxy ] && [ "$port" = 9999 ]; then
+    cat >&2 <<EOF
+Warning: apt-proxy appears to be installed also.
+         For compatibility with client sources.list files,
+         approx uses the same port (9999) by default.
+         Please stop or remove apt-proxy, or configure
+         one of them to listen on a different port.
+EOF
 fi
 
 #DEBHELPER#

Modified: trunk/projects/approx/debian/approx.postrm
===================================================================
--- trunk/projects/approx/debian/approx.postrm	2005-04-27 22:39:34 UTC (rev 1324)
+++ trunk/projects/approx/debian/approx.postrm	2005-04-28 00:28:11 UTC (rev 1325)
@@ -6,10 +6,13 @@
     exit 0
 fi
 
-rm -r /var/cache/approx
+rm -rf /var/cache/approx
 
 if getent passwd approx >/dev/null; then
     deluser --quiet approx
+fi
+
+if getent group approx >/dev/null; then
     delgroup --quiet approx
 fi
 

Modified: trunk/projects/approx/debian/changelog
===================================================================
--- trunk/projects/approx/debian/changelog	2005-04-27 22:39:34 UTC (rev 1324)
+++ trunk/projects/approx/debian/changelog	2005-04-28 00:28:11 UTC (rev 1325)
@@ -1,3 +1,12 @@
+approx (1.13) unstable; urgency=low
+
+  * make sure /var/cache/approx exists before trying to chown it
+    (closes: #306621)
+  * no longer allow the cache directory to be specified in approx.conf;
+    always use /var/cache/approx (which can be a symlink)
+
+ -- Eric Cooper <ecc@cmu.edu>  Wed, 27 Apr 2005 18:39:13 -0400
+
 approx (1.12) unstable; urgency=low
 
   * New description, from suggestions by

Modified: trunk/projects/approx/default_config.ml
===================================================================
--- trunk/projects/approx/default_config.ml	2005-04-27 22:39:34 UTC (rev 1324)
+++ trunk/projects/approx/default_config.ml	2005-04-28 00:28:11 UTC (rev 1325)
@@ -5,10 +5,10 @@
 open Config
 
 let config_file = "/etc/approx/approx.conf"
+let cache_dir = "/var/cache/approx"
 
 let () = read config_file
 
-let cache = get "cache" ~default: "/var/cache/approx"
-let port = get_int "port" ~default: 9999
+let port = get_int "port" ~default: 9999 (* for compatibility with apt-proxy *)
 let interval = get_int "interval" ~default: 720 (* minutes *)
 let debug = get_bool "debug" ~default: false

Modified: trunk/projects/approx/default_config.mli
===================================================================
--- trunk/projects/approx/default_config.mli	2005-04-27 22:39:34 UTC (rev 1324)
+++ trunk/projects/approx/default_config.mli	2005-04-28 00:28:11 UTC (rev 1325)
@@ -3,7 +3,7 @@
    Released under the GNU General Public License *)
 
 val config_file : string
-val cache : string
+val cache_dir : string
 val port : int
 val interval : int
 val debug : bool

Modified: trunk/projects/approx/gc_approx.ml
===================================================================
--- trunk/projects/approx/gc_approx.ml	2005-04-27 22:39:34 UTC (rev 1324)
+++ trunk/projects/approx/gc_approx.ml	2005-04-28 00:28:11 UTC (rev 1325)
@@ -58,7 +58,7 @@
     | "Packages" | "Packages.gz" -> roots := file :: !roots
     | _ -> ()
   in
-  Config.iter (fun dir _ -> treewalk find (cache ^/ dir))
+  Config.iter (fun dir _ -> treewalk find (cache_dir ^/ dir))
 
 (* Extract the distribution and relative filename
    from the absolute pathname of a file in the cache.
@@ -68,7 +68,7 @@
        ("debian", "pool/main/...") *)
 
 let split_cache_pathname path =
-   split_path (substring path ~from: (String.length cache))
+   split_path (substring path ~from: (String.length cache_dir))
 
 (* The cache is probably only a small subset of all the files in
    the Debian archive, so  we start with a table of filenames
@@ -103,7 +103,7 @@
   let record file =
     if is_candidate file then set_status file Unmarked
   in
-  treewalk record cache
+  treewalk record cache_dir
 
 (* Handle the case of filename fields of the form ./path  *)
 
@@ -152,7 +152,7 @@
 let mark_package package =
   if !verbose then (print_string "# "; print_endline package);
   let dist, file = split_cache_pathname package in
-  let prefix = cache ^/ dist in
+  let prefix = cache_dir ^/ dist in
   try
     Package.iter (mark_file prefix) package
   with Failure "decompress" ->