diff options
Diffstat (limited to 'apt-pkg/contrib')
-rw-r--r-- | apt-pkg/contrib/fileutl.cc | 11 | ||||
-rw-r--r-- | apt-pkg/contrib/fileutl.h | 3 |
2 files changed, 12 insertions, 2 deletions
diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc index 2a3b8a87d..91aecee65 100644 --- a/apt-pkg/contrib/fileutl.cc +++ b/apt-pkg/contrib/fileutl.cc @@ -669,7 +669,7 @@ bool FileFd::Open(string FileName,OpenMode Mode, unsigned long Perms) } break; - case WriteEmpty: + case WriteAtomic: { Flags |= Replace; char *name = strdup((FileName + ".XXXXXX").c_str()); @@ -678,6 +678,15 @@ bool FileFd::Open(string FileName,OpenMode Mode, unsigned long Perms) free(name); break; } + + case WriteEmpty: + { + struct stat Buf; + if (lstat(FileName.c_str(),&Buf) == 0 && S_ISLNK(Buf.st_mode)) + unlink(FileName.c_str()); + iFd = open(FileName.c_str(),O_RDWR | O_CREAT | O_TRUNC,Perms); + break; + } case WriteExists: iFd = open(FileName.c_str(),O_RDWR); diff --git a/apt-pkg/contrib/fileutl.h b/apt-pkg/contrib/fileutl.h index 62705478d..cb4655798 100644 --- a/apt-pkg/contrib/fileutl.h +++ b/apt-pkg/contrib/fileutl.h @@ -46,7 +46,8 @@ class FileFd gzFile gz; public: - enum OpenMode {ReadOnly,WriteEmpty,WriteExists,WriteAny,WriteTemp,ReadOnlyGzip}; + enum OpenMode {ReadOnly,WriteEmpty,WriteExists,WriteAny,WriteTemp,ReadOnlyGzip, + WriteAtomic}; inline bool Read(void *To,unsigned long Size,bool AllowEof) { |