SHA256
3
0
forked from pool/timezone
timezone/tzcode-symlink.patch
Marcus Meissner 6620a7ba51 Accepting request 307993 from home:leonardocf:branches:Base:System
- Fix check for empty components in absolute path
- Fix post-install script to overwrite the temporary file when
  attempting to create /etc/localtime as a hard link [bsc#928841]
- Update to 2015d [bsc#928584, bsc#928246]

OBS-URL: https://build.opensuse.org/request/show/307993
OBS-URL: https://build.opensuse.org/package/show/Base:System/timezone?expand=0&rev=160
2015-05-19 15:52:15 +00:00

90 lines
2.8 KiB
Diff

This patch is used on openSUSE 12.2 or newer. Nowadays,
/etc/localtime is by default a symbolic link to a zone
file in /usr/share/zoneinfo.
By default, zic tries the following approaches to create
/etc/localtime:
1. Hard link
2. Symbolic link
3. File copy
This patch changes the logic slightly: keep using symbolic
links if /etc/localtime is already one. If it isn't, use
the default order as listed above.
Index: timezone-2015d/zic.c
===================================================================
--- timezone-2015d.orig/zic.c
+++ timezone-2015d/zic.c
@@ -104,7 +104,7 @@ static int addtype(zic_t, char const *,
static void leapadd(zic_t, bool, int, int);
static void adjleap(void);
static void associate(void);
-static void dolink(const char * fromfield, const char * tofield);
+static void dolink(const char * fromfield, const char * tofield, int defaultsymlink);
static char ** getfields(char * buf);
static zic_t gethms(const char * string, const char * errstring,
bool);
@@ -629,7 +629,7 @@ _("%s: More than one -L option specified
*/
for (i = 0; i < nlinks; ++i) {
eat(links[i].l_filename, links[i].l_linenum);
- dolink(links[i].l_from, links[i].l_to);
+ dolink(links[i].l_from, links[i].l_to, false);
if (noise)
for (j = 0; j < nlinks; ++j)
if (strcmp(links[i].l_to,
@@ -638,11 +638,11 @@ _("%s: More than one -L option specified
}
if (lcltime != NULL) {
eat(_("command line"), 1);
- dolink(lcltime, TZDEFAULT);
+ dolink(lcltime, TZDEFAULT, true);
}
if (psxrules != NULL) {
eat(_("command line"), 1);
- dolink(psxrules, TZDEFRULES);
+ dolink(psxrules, TZDEFRULES, false);
}
if (warnings && (ferror(stderr) || fclose(stderr) != 0))
return EXIT_FAILURE;
@@ -735,14 +735,17 @@ relname(char const *dir, char const *bas
}
static void
-dolink(const char *const fromfield, const char *const tofield)
+dolink(const char *const fromfield, const char *const tofield, int defaultsymlink)
{
+ struct stat st;
register char * fromname;
register char * toname;
register int fromisdir;
fromname = relname(directory, fromfield);
toname = relname(directory, tofield);
+ if (lstat(fromname, &st) == 0 && S_ISLNK(st.st_mode))
+ defaultsymlink = true;
/*
** We get to be careful here since
** there's a fair chance of root running us.
@@ -756,14 +759,14 @@ dolink(const char *const fromfield, cons
}
if (itsdir(toname) <= 0)
remove(toname);
- if (link(fromname, toname) != 0) {
+ if (defaultsymlink || link(fromname, toname) != 0) {
int result;
if (! mkdirs(toname))
exit(EXIT_FAILURE);
-
- result = link(fromname, toname);
- if (result != 0) {
+ if (!defaultsymlink)
+ result = link(fromname, toname);
+ if ((defaultsymlink || (!defaultsymlink && result != 0))) {
const char *s = fromname;
const char *t;
char *p;