diff --git a/dos2unix-bnc#488261-dont_destroy_original.patch b/dos2unix-bnc#488261-dont_destroy_original.patch new file mode 100644 index 0000000..1fa773e --- /dev/null +++ b/dos2unix-bnc#488261-dont_destroy_original.patch @@ -0,0 +1,143 @@ +Index: dos2unix.c +=================================================================== +--- dos2unix.c.orig ++++ dos2unix.c +@@ -69,6 +69,7 @@ static int macmode = 0; + #ifdef __MSDOS__ + # include + #endif __MSDOS__ ++#include + #include + #include + #include +@@ -247,6 +248,39 @@ int ConvertDosToUnix(FILE* ipInF, FILE* + return RetVal; + } + ++static int MakeTempFileFrom(const char *OutFN, char **fname_ret) ++{ ++ char *cpy = strdup(OutFN); ++ char *dir = NULL; ++ size_t fname_len = 0; ++ char *fname_str = NULL; ++ int fd = -1; ++ ++ *fname_ret = NULL; ++ ++ if (!cpy) ++ goto make_failed; ++ ++ dir = dirname(cpy); ++ ++ fname_len = strlen(dir) + strlen("/d2utmpXXXXXX") + sizeof (char); ++ if (!(fname_str = malloc(fname_len))) ++ goto make_failed; ++ sprintf(fname_str, "%s%s", dir, "/d2utmpXXXXXX"); ++ *fname_ret = fname_str; ++ ++ free(cpy); ++ ++ if ((fd = mkstemp(fname_str)) == -1) ++ goto make_failed; ++ ++ return (fd); ++ ++ make_failed: ++ free(*fname_ret); ++ *fname_ret = NULL; ++ return (-1); ++} + + /* convert file ipInFN to UNIX format text and write to file ipOutFN + * RetVal: 0 if success +@@ -257,7 +291,7 @@ int ConvertDosToUnixNewFile(char *ipInFN + int RetVal = 0; + FILE *InF = NULL; + FILE *TempF = NULL; +- char TempPath[16]; ++ char *TempPath; + struct stat StatBuf; + struct utimbuf UTimeBuf; + int fd; +@@ -266,8 +300,7 @@ int ConvertDosToUnixNewFile(char *ipInFN + if ((ipFlag->KeepDate) && stat(ipInFN, &StatBuf)) + RetVal = -1; + +- strcpy (TempPath, "./d2utmpXXXXXX"); +- if((fd=mkstemp (TempPath))<0) { ++ if((fd = MakeTempFileFrom(ipOutFN, &TempPath))<0) { + perror("Failed to open output temp file"); + RetVal = -1; + } +@@ -284,6 +317,7 @@ int ConvertDosToUnixNewFile(char *ipInFN + if ((!RetVal) && (InF) && ((TempF=OpenOutFile(fd)) == NULL)) + { + fclose (InF); ++ InF = NULL; + RetVal = -1; + } + +@@ -317,9 +351,6 @@ int ConvertDosToUnixNewFile(char *ipInFN + /* can rename temp file to out file? */ + if (!RetVal) + { +- if (stat(ipOutFN, &StatBuf) == 0) +- unlink(ipOutFN); +- + if ((rename(TempPath, ipOutFN) == -1) && (!ipFlag->Quiet)) + { + fprintf(stderr, "dos2unix: problems renaming '%s' to '%s'\n", TempPath, ipOutFN); +@@ -327,6 +358,7 @@ int ConvertDosToUnixNewFile(char *ipInFN + RetVal = -1; + } + } ++ free(TempPath); + return RetVal; + } + +@@ -342,7 +374,7 @@ int ConvertDosToUnixOldFile(char* ipInFN + int RetVal = 0; + FILE *InF = NULL; + FILE *TempF = NULL; +- char TempPath[16]; ++ char *TempPath; + struct stat StatBuf; + struct utimbuf UTimeBuf; + mode_t mode = S_IRUSR | S_IWUSR; +@@ -354,8 +386,7 @@ int ConvertDosToUnixOldFile(char* ipInFN + else + mode = StatBuf.st_mode; + +- strcpy (TempPath, "./u2dtmpXXXXXX"); +- if((fd=mkstemp (TempPath))<0) { ++ if((fd = MakeTempFileFrom(ipInFN, &TempPath))<0) { + perror("Failed to open output temp file"); + RetVal = -1; + } +@@ -375,6 +406,7 @@ int ConvertDosToUnixOldFile(char* ipInFN + if ((!RetVal) && (InF) && ((TempF=OpenOutFile(fd)) == NULL)) + { + fclose (InF); ++ InF = NULL; + RetVal = -1; + } + +@@ -402,10 +434,6 @@ int ConvertDosToUnixOldFile(char* ipInFN + RetVal = -1; + } + +- /* can delete in file? */ +- if ((!RetVal) && (unlink(ipInFN) == -1)) +- RetVal = -1; +- + /* any error? */ + if ((RetVal) && (unlink(TempPath))) + RetVal = -1; +@@ -420,6 +448,7 @@ int ConvertDosToUnixOldFile(char* ipInFN + } + RetVal = -1; + } ++ free(TempPath); + return RetVal; + } + diff --git a/dos2unix.changes b/dos2unix.changes index 6737b3d..7105177 100644 --- a/dos2unix.changes +++ b/dos2unix.changes @@ -1,3 +1,9 @@ +------------------------------------------------------------------- +Mon Apr 20 15:03:31 CEST 2009 - pth@suse.de + +- Don't destroy original file if the output is on a different file + system (bnc#488261). + ------------------------------------------------------------------- Tue Dec 9 17:10:36 CET 2008 - schwab@suse.de diff --git a/dos2unix.spec b/dos2unix.spec index 81498be..d8d51c5 100644 --- a/dos2unix.spec +++ b/dos2unix.spec @@ -1,7 +1,7 @@ # # spec file for package dos2unix (Version 3.1) # -# Copyright (c) 2008 SUSE LINUX Products GmbH, Nuernberg, Germany. +# Copyright (c) 2009 SUSE LINUX Products GmbH, Nuernberg, Germany. # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed @@ -20,13 +20,14 @@ Name: dos2unix Summary: A DOS to UNIX Text Converter Version: 3.1 -Release: 438 +Release: 439 Group: Productivity/Text/Convertors License: BSD 3-Clause Source: %{name}-%{version}.tar.bz2 Patch0: %{name}-%{version}.patch Patch1: dos2unix-3.1-segfault.patch Patch2: dos2unix-3.1-preserve-file-modes.patch +Patch3: dos2unix-bnc#488261-dont_destroy_original.patch BuildRoot: %{_tmppath}/%{name}-%{version}-build %description @@ -44,6 +45,7 @@ Authors: %patch0 -p1 -b .orig %patch1 -p1 -b .segf %patch2 -b .fmode +%patch3 perl -pi -e 's,(#endif|#else)[^ ]*(.*),$1 /* $2 */,g' *.[ch] %build @@ -69,6 +71,9 @@ ln -s dos2unix.1 $RPM_BUILD_ROOT%{_mandir}/man1/mac2unix.1 rm -rf $RPM_BUILD_ROOT %changelog +* Mon Apr 20 2009 pth@suse.de +- Don't destroy original file if the output is on a different file + system (bnc#488261). * Tue Dec 09 2008 schwab@suse.de - Fix last change. * Mon Sep 15 2008 ro@suse.de