- Don't just delete the original file when destination and current
directory are on different filesystems (#65548, #123069, patch by James Antill) - Fix return type of StripDelimiter in dos2unix-3.1-safeconv.patch (#136148)
This commit is contained in:
parent
df1bda2b1e
commit
c23006003d
@ -10,7 +10,7 @@ diff -Nur dos2unix-3.1-orig/dos2unix.c dos2unix-3.1/dos2unix.c
|
||||
}
|
||||
|
||||
|
||||
+int StripDelimiter(FILE* ipInF, FILE* ipOutF, CFlag *ipFlag, int CurChar)
|
||||
+void StripDelimiter(FILE* ipInF, FILE* ipOutF, CFlag *ipFlag, int CurChar)
|
||||
+{
|
||||
+ int TempNextChar;
|
||||
+ /* Don't modify Mac files when in dos2unix mode. */
|
||||
|
141
dos2unix-3.1-tmppath.patch
Normal file
141
dos2unix-3.1-tmppath.patch
Normal file
@ -0,0 +1,141 @@
|
||||
--- dos2unix-3.1/dos2unix.c.tmppath 2004-10-20 16:00:00.342561008 +0200
|
||||
+++ dos2unix-3.1/dos2unix.c 2004-10-20 16:01:42.210074792 +0200
|
||||
@@ -69,6 +69,7 @@
|
||||
#ifdef __MSDOS__
|
||||
# include <dir.h>
|
||||
#endif __MSDOS__
|
||||
+#include <libgen.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -267,6 +268,39 @@
|
||||
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");
|
||||
+ 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
|
||||
@@ -277,7 +311,7 @@
|
||||
int RetVal = 0;
|
||||
FILE *InF = NULL;
|
||||
FILE *TempF = NULL;
|
||||
- char TempPath[16];
|
||||
+ char *TempPath;
|
||||
struct stat StatBuf;
|
||||
struct utimbuf UTimeBuf;
|
||||
int fd;
|
||||
@@ -286,8 +320,7 @@
|
||||
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;
|
||||
}
|
||||
@@ -304,6 +337,7 @@
|
||||
if ((!RetVal) && (InF) && ((TempF=OpenOutFile(fd)) == NULL))
|
||||
{
|
||||
fclose (InF);
|
||||
+ InF = NULL;
|
||||
RetVal = -1;
|
||||
}
|
||||
|
||||
@@ -337,9 +371,6 @@
|
||||
/* 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);
|
||||
@@ -347,6 +378,7 @@
|
||||
RetVal = -1;
|
||||
}
|
||||
}
|
||||
+ free(TempPath);
|
||||
return RetVal;
|
||||
}
|
||||
|
||||
@@ -362,7 +394,7 @@
|
||||
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;
|
||||
@@ -374,8 +406,7 @@
|
||||
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;
|
||||
}
|
||||
@@ -395,6 +426,7 @@
|
||||
if ((!RetVal) && (InF) && ((TempF=OpenOutFile(fd)) == NULL))
|
||||
{
|
||||
fclose (InF);
|
||||
+ InF = NULL;
|
||||
RetVal = -1;
|
||||
}
|
||||
|
||||
@@ -422,10 +454,6 @@
|
||||
RetVal = -1;
|
||||
}
|
||||
|
||||
- /* can delete in file? */
|
||||
- if ((!RetVal) && (unlink(ipInFN) == -1))
|
||||
- RetVal = -1;
|
||||
-
|
||||
/* any error? */
|
||||
if ((RetVal) && (unlink(TempPath)))
|
||||
RetVal = -1;
|
||||
@@ -440,6 +468,7 @@
|
||||
}
|
||||
RetVal = -1;
|
||||
}
|
||||
+ free(TempPath);
|
||||
return RetVal;
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
Summary: Text file format converter
|
||||
Name: dos2unix
|
||||
Version: 3.1
|
||||
Release: 20
|
||||
Release: 21
|
||||
Group: Applications/Text
|
||||
License: Freely distributable
|
||||
Source: %{name}-%{version}.tar.bz2
|
||||
@ -10,6 +10,7 @@ Patch1: dos2unix-3.1-segfault.patch
|
||||
Patch2: dos2unix-3.1-safeconv.patch
|
||||
Patch3: dos2unix-3.1-manpage-update-57507.patch
|
||||
Patch4: dos2unix-3.1-preserve-file-modes.patch
|
||||
Patch5: dos2unix-3.1-tmppath.patch
|
||||
|
||||
Buildroot: %{_tmppath}/%{name}-%{version}-root
|
||||
|
||||
@ -23,6 +24,7 @@ Dos2unix converts DOS or MAC text files to UNIX format.
|
||||
%patch2 -p1 -b .safeconv
|
||||
%patch3 -p1 -b .manpage-update-57507
|
||||
%patch4 -p1 -b .preserve-file-modes
|
||||
%patch5 -p1 -b .tmppath
|
||||
|
||||
for I in *.[ch]; do
|
||||
sed -e 's,#endif.*,#endif,g' -e 's,#else.*,#else,g' $I > $I.new
|
||||
@ -54,6 +56,11 @@ install -m444 mac2unix.1 $RPM_BUILD_ROOT%{_mandir}/man1
|
||||
rm -rf $RPM_BUILD_ROOT
|
||||
|
||||
%changelog
|
||||
* Wed Oct 20 2004 Miloslav Trmac <mitr@redhat.com> - 3.1-21
|
||||
- Don't just delete the original file when destination and current directory
|
||||
are on different filesystems (#65548, #123069, patch by James Antill)
|
||||
- Fix return type of StripDelimiter in dos2unix-3.1-safeconv.patch (#136148)
|
||||
|
||||
* Wed Oct 6 2004 Mike A. Harris <mharris@redhat.com> 3.1-20
|
||||
- Added dos2unix-3.1-manpage-update-57507.patch to fix manpage (#57507)
|
||||
- Added dos2unix-3.1-preserve-file-modes.patch to properly preserve file
|
||||
|
Loading…
Reference in New Issue
Block a user