Pino Toscano
2014-Feb-18 11:55 UTC
[Libguestfs] [PATCH] builder: move the XDG path handling in an own file
Just code motion and renaming, no actual behaviour changes. --- builder/Makefile.am | 2 ++ builder/cmdline.ml | 9 +-------- builder/paths.ml | 26 ++++++++++++++++++++++++++ po/POTFILES-ml | 1 + 4 files changed, 30 insertions(+), 8 deletions(-) create mode 100644 builder/paths.ml diff --git a/builder/Makefile.am b/builder/Makefile.am index 6313bad..23336c0 100644 --- a/builder/Makefile.am +++ b/builder/Makefile.am @@ -48,6 +48,7 @@ SOURCES = \ index-parser-c.c \ list_entries.mli \ list_entries.ml \ + paths.ml \ pxzcat.ml \ pxzcat.mli \ pxzcat-c.c \ @@ -91,6 +92,7 @@ OBJECTS = \ pxzcat.cmx \ setlocale-c.o \ setlocale.cmx \ + paths.cmx \ get_kernel.cmx \ downloader.cmx \ sigchecker.cmx \ diff --git a/builder/cmdline.ml b/builder/cmdline.ml index a6cb6c5..e9e47ae 100644 --- a/builder/cmdline.ml +++ b/builder/cmdline.ml @@ -30,13 +30,6 @@ open Printf let prog = Filename.basename Sys.executable_name -let default_cachedir - try Some (Sys.getenv "XDG_CACHE_HOME" // "virt-builder") - with Not_found -> - try Some (Sys.getenv "HOME" // ".cache" // "virt-builder") - with Not_found -> - None (* no cache directory *) - let default_source = "http://libguestfs.org/download/builder/index.asc" let parse_cmdline () @@ -61,7 +54,7 @@ let parse_cmdline () in let attach_disk s = attach := (!attach_format, s) :: !attach in - let cache = ref default_cachedir in + let cache = ref Paths.xdg_cache_home in let set_cache arg = cache := Some arg in let no_cache () = cache := None in diff --git a/builder/paths.ml b/builder/paths.ml new file mode 100644 index 0000000..66e8922 --- /dev/null +++ b/builder/paths.ml @@ -0,0 +1,26 @@ +(* virt-builder + * Copyright (C) 2014 Red Hat Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + *) + +open Common_utils + +let xdg_cache_home + try Some (Sys.getenv "XDG_CACHE_HOME" // "virt-builder") + with Not_found -> + try Some (Sys.getenv "HOME" // ".cache" // "virt-builder") + with Not_found -> + None (* no cache directory *) diff --git a/po/POTFILES-ml b/po/POTFILES-ml index 7937728..301fe81 100644 --- a/po/POTFILES-ml +++ b/po/POTFILES-ml @@ -4,6 +4,7 @@ builder/downloader.ml builder/get_kernel.ml builder/index_parser.ml builder/list_entries.ml +builder/paths.ml builder/pxzcat.ml builder/setlocale.ml builder/sigchecker.ml -- 1.8.3.1
Richard W.M. Jones
2014-Feb-18 13:46 UTC
Re: [Libguestfs] [PATCH] builder: move the XDG path handling in an own file
On Tue, Feb 18, 2014 at 12:55:50PM +0100, Pino Toscano wrote:> Just code motion and renaming, no actual behaviour changes. > --- > builder/Makefile.am | 2 ++ > builder/cmdline.ml | 9 +-------- > builder/paths.ml | 26 ++++++++++++++++++++++++++ > po/POTFILES-ml | 1 + > 4 files changed, 30 insertions(+), 8 deletions(-) > create mode 100644 builder/paths.ml > > diff --git a/builder/Makefile.am b/builder/Makefile.am > index 6313bad..23336c0 100644 > --- a/builder/Makefile.am > +++ b/builder/Makefile.am > @@ -48,6 +48,7 @@ SOURCES = \ > index-parser-c.c \ > list_entries.mli \ > list_entries.ml \ > + paths.ml \ > pxzcat.ml \ > pxzcat.mli \ > pxzcat-c.c \ > @@ -91,6 +92,7 @@ OBJECTS = \ > pxzcat.cmx \ > setlocale-c.o \ > setlocale.cmx \ > + paths.cmx \ > get_kernel.cmx \ > downloader.cmx \ > sigchecker.cmx \ > diff --git a/builder/cmdline.ml b/builder/cmdline.ml > index a6cb6c5..e9e47ae 100644 > --- a/builder/cmdline.ml > +++ b/builder/cmdline.ml > @@ -30,13 +30,6 @@ open Printf > > let prog = Filename.basename Sys.executable_name > > -let default_cachedir > - try Some (Sys.getenv "XDG_CACHE_HOME" // "virt-builder") > - with Not_found -> > - try Some (Sys.getenv "HOME" // ".cache" // "virt-builder") > - with Not_found -> > - None (* no cache directory *) > - > let default_source = "http://libguestfs.org/download/builder/index.asc" > > let parse_cmdline () > @@ -61,7 +54,7 @@ let parse_cmdline () > in > let attach_disk s = attach := (!attach_format, s) :: !attach in > > - let cache = ref default_cachedir in > + let cache = ref Paths.xdg_cache_home in > let set_cache arg = cache := Some arg in > let no_cache () = cache := None in > > diff --git a/builder/paths.ml b/builder/paths.ml > new file mode 100644 > index 0000000..66e8922 > --- /dev/null > +++ b/builder/paths.ml > @@ -0,0 +1,26 @@ > +(* virt-builder > + * Copyright (C) 2014 Red Hat Inc. > + * > + * This program is free software; you can redistribute it and/or modify > + * it under the terms of the GNU General Public License as published by > + * the Free Software Foundation; either version 2 of the License, or > + * (at your option) any later version. > + * > + * This program is distributed in the hope that it will be useful, > + * but WITHOUT ANY WARRANTY; without even the implied warranty of > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > + * GNU General Public License for more details. > + * > + * You should have received a copy of the GNU General Public License along > + * with this program; if not, write to the Free Software Foundation, Inc., > + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. > + *) > + > +open Common_utils > + > +let xdg_cache_home > + try Some (Sys.getenv "XDG_CACHE_HOME" // "virt-builder") > + with Not_found -> > + try Some (Sys.getenv "HOME" // ".cache" // "virt-builder") > + with Not_found -> > + None (* no cache directory *) > diff --git a/po/POTFILES-ml b/po/POTFILES-ml > index 7937728..301fe81 100644 > --- a/po/POTFILES-ml > +++ b/po/POTFILES-ml > @@ -4,6 +4,7 @@ builder/downloader.ml > builder/get_kernel.ml > builder/index_parser.ml > builder/list_entries.ml > +builder/paths.ml > builder/pxzcat.ml > builder/setlocale.ml > builder/sigchecker.ml > -- > 1.8.3.1ACK. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones virt-p2v converts physical machines to virtual machines. Boot with a live CD or over the network (PXE) and turn machines into KVM guests. http://libguestfs.org/virt-v2v