librelist archives

« back to archive

"Handling files that should persist over formula upgrades"

"Handling files that should persist over formula upgrades"

From:
Brooks Clark
Date:
2011-08-18 @ 00:52
Can anyone provide a little more detail on how to handle the above topic? 
The formula cookbook is a little thin in this area. 

I'm trying to write a formula for a program that installs sqlite3 
databases in /usr/local/var and configuration files in /usr/local/etc. I 
am able to compile and install the software using homebrew, but when 
upgrading, I'd like to be able to check if the files already exist. If 
they do, I don't want to overwrite them. If they don't, I do want to go 
ahead and install them. 


-- 
Brooks Clark
Sent with Sparrow (http://www.sparrowmailapp.com/?sig)

Re: [homebrew] "Handling files that should persist over formula upgrades"

From:
Jack Nagel
Date:
2011-08-18 @ 01:38
On Wed, Aug 17, 2011 at 7:52 PM, Brooks Clark <brooks@clarksonline.net> wrote:
> Can anyone provide a little more detail on how to handle the above topic?
> The formula cookbook is a little thin in this area.
> I'm trying to write a formula for a program that installs sqlite3 databases
> in /usr/local/var and configuration files in /usr/local/etc. I am able to
> compile and install the software using homebrew, but when upgrading, I'd
> like to be able to check if the files already exist. If they do, I don't
> want to overwrite them. If they don't, I do want to go ahead and install
> them.

In Homebrew formulae, you can use the variables 'var' and 'etc', which
are shorthand for HOMEBREW_PREFIX+'var' and HOMEBREW_PREFIX+'etc';
installing things to these locations (i.e., not in the formula's keg
in the Cellar) will allow them to persist over upgrades.

Some software will do the right thing and check for the existence of
these files during the build process, and avoid overwriting them.
Though if you are installing the files 'manually', e.g. with explicit
code in the formula, you might have to do something like
'File.exists?'.

Jack

Re: [homebrew] "Handling files that should persist over formula upgrades"

From:
Brooks Clark
Date:
2011-08-18 @ 01:46
Thanks. Can you point me to any example formulas that use this approach? 

What I'd like to do is to install the files in the Cellar, then check if 
the files exist in /usr/local/var and /usr/local/etc. Is there any way to 
prevent the links from being created for these directories? 

-- 
Brooks Clark
Sent with Sparrow (http://www.sparrowmailapp.com/?sig)

On Wednesday, August 17, 2011 at 8:38 PM, Jack Nagel wrote:

> On Wed, Aug 17, 2011 at 7:52 PM, Brooks Clark <brooks@clarksonline.net 
(mailto:brooks@clarksonline.net)> wrote:
> > Can anyone provide a little more detail on how to handle the above topic?
> > The formula cookbook is a little thin in this area.
> > I'm trying to write a formula for a program that installs sqlite3 databases
> > in /usr/local/var and configuration files in /usr/local/etc. I am able to
> > compile and install the software using homebrew, but when upgrading, I'd
> > like to be able to check if the files already exist. If they do, I don't
> > want to overwrite them. If they don't, I do want to go ahead and install
> > them.
> 
> In Homebrew formulae, you can use the variables 'var' and 'etc', which
> are shorthand for HOMEBREW_PREFIX+'var' and HOMEBREW_PREFIX+'etc';
> installing things to these locations (i.e., not in the formula's keg
> in the Cellar) will allow them to persist over upgrades.
> 
> Some software will do the right thing and check for the existence of
> these files during the build process, and avoid overwriting them.
> Though if you are installing the files 'manually', e.g. with explicit
> code in the formula, you might have to do something like
> 'File.exists?'.
> 
> Jack

Re: [homebrew] "Handling files that should persist over formula upgrades"

From:
Jack Nagel
Date:
2011-08-18 @ 01:59
On Wed, Aug 17, 2011 at 8:46 PM, Brooks Clark <brooks@clarksonline.net> wrote:
> Thanks. Can you point me to any example formulas that use this approach?

Grepping the Library/Formula directory for '#{var}' or '#{etc}', would
be a good place to start.

> What I'd like to do is to install the files in the Cellar, then check if the
> files exist in /usr/local/var and /usr/local/etc. Is there any way to
> prevent the links from being created for these directories?

If you use the 'var' and 'etc' variables, links won't be made in
/usr/local/{var, etc} (more correctly, HOMEBREW_PREFIX+{'var',
'etc'}), and the files will persist across upgrades. But if you use
the 'prefix' variable (e.g. prefix+'etc'), they will be installed to
the Cellar and symlinked into the respective directories, and then
they _will_ be removed during upgrades.

AFAIK there isn't a (trivial) way to selectively disable linking of
certain files. Maybe there is something clever that you can do,
though.

Jack