~ubuntu-branches/ubuntu/jaunty/cmake/jaunty-security

« back to all changes in this revision

Viewing changes to Source/cmGeneratedFileStream.cxx

  • Committer: Bazaar Package Importer
  • Author(s): A. Maitland Bottoms
  • Date: 2006-06-18 16:34:11 UTC
  • mfrom: (1.4.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20060618163411-pi234s3v6jwlcmof
Tags: 2.4.2-1
* New upstream release (Closes: #338324)
* Put cmake .vim files into /usr/share/vim/addons/plugin/
  where they can be used. (Closes: #366663)
* Install cmake-mode.el so it can be used. (Closes: #366664)
* Ensure cmake FindKDE locates KDE libraries on Debian
  based distributions.

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
  Program:   CMake - Cross-Platform Makefile Generator
4
4
  Module:    $RCSfile: cmGeneratedFileStream.cxx,v $
5
5
  Language:  C++
6
 
  Date:      $Date: 2005/05/10 15:11:28 $
7
 
  Version:   $Revision: 1.9 $
 
6
  Date:      $Date: 2006/05/11 02:15:09 $
 
7
  Version:   $Revision: 1.15.2.1 $
8
8
 
9
9
  Copyright (c) 2002 Kitware, Inc., Insight Consortium.  All rights reserved.
10
10
  See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
39
39
//----------------------------------------------------------------------------
40
40
cmGeneratedFileStream::cmGeneratedFileStream(const char* name, bool quiet):
41
41
  cmGeneratedFileStreamBase(name),
42
 
  Stream(m_TempName.c_str())
 
42
  Stream(TempName.c_str())
43
43
{
44
44
  // Check if the file opened.
45
45
  if(!*this && !quiet)
46
46
    {
47
 
    cmSystemTools::Error("Cannot open file for write: ", m_TempName.c_str());
 
47
    cmSystemTools::Error("Cannot open file for write: ", 
 
48
                         this->TempName.c_str());
48
49
    cmSystemTools::ReportLastSystemError("");
49
50
    }
50
51
}
57
58
  // stream will be destroyed which will close the temporary file.
58
59
  // Finally the base destructor will be called to replace the
59
60
  // destination file.
60
 
  m_Okay = (*this)?true:false;
 
61
  this->Okay = (*this)?true:false;
61
62
}
62
63
 
63
64
//----------------------------------------------------------------------------
64
65
cmGeneratedFileStream&
65
 
cmGeneratedFileStream::Open(const char* name, bool quiet)
 
66
cmGeneratedFileStream::Open(const char* name, bool quiet, bool binaryFlag)
66
67
{
67
68
  // Store the file name and construct the temporary file name.
68
69
  this->cmGeneratedFileStreamBase::Open(name);
69
70
 
70
71
  // Open the temporary output file.
71
 
  this->Stream::open(m_TempName.c_str());
 
72
  if ( binaryFlag )
 
73
    {
 
74
    this->Stream::open(this->TempName.c_str(), 
 
75
                       std::ios::out | std::ios::binary);
 
76
    }
 
77
  else
 
78
    {
 
79
    this->Stream::open(this->TempName.c_str(), std::ios::out);
 
80
    }
72
81
 
73
82
  // Check if the file opened.
74
83
  if(!*this && !quiet)
75
84
    {
76
 
    cmSystemTools::Error("Cannot open file for write: ", m_TempName.c_str());
 
85
    cmSystemTools::Error("Cannot open file for write: ", 
 
86
                         this->TempName.c_str());
77
87
    cmSystemTools::ReportLastSystemError("");
78
88
    }
79
89
  return *this;
84
94
cmGeneratedFileStream::Close()
85
95
{
86
96
  // Save whether the temporary output file is valid before closing.
87
 
  m_Okay = (*this)?true:false;
 
97
  this->Okay = (*this)?true:false;
88
98
 
89
99
  // Close the temporary output file.
90
100
  this->Stream::close();
98
108
//----------------------------------------------------------------------------
99
109
void cmGeneratedFileStream::SetCopyIfDifferent(bool copy_if_different)
100
110
{
101
 
  m_CopyIfDifferent = copy_if_different;
 
111
  this->CopyIfDifferent = copy_if_different;
102
112
}
103
113
 
104
114
//----------------------------------------------------------------------------
105
115
void cmGeneratedFileStream::SetCompression(bool compression)
106
116
{
107
 
  m_Compress = compression;
 
117
  this->Compress = compression;
 
118
}
 
119
 
 
120
//----------------------------------------------------------------------------
 
121
void cmGeneratedFileStream::SetCompressionExtraExtension(bool ext)
 
122
{
 
123
  this->CompressExtraExtension = ext;
108
124
}
109
125
 
110
126
//----------------------------------------------------------------------------
111
127
cmGeneratedFileStreamBase::cmGeneratedFileStreamBase():
112
 
  m_Name(),
113
 
  m_TempName(),
114
 
  m_CopyIfDifferent(false),
115
 
  m_Okay(false),
116
 
  m_Compress(false)
 
128
  Name(),
 
129
  TempName(),
 
130
  CopyIfDifferent(false),
 
131
  Okay(false),
 
132
  Compress(false),
 
133
  CompressExtraExtension(true)
117
134
{
118
135
}
119
136
 
120
137
//----------------------------------------------------------------------------
121
138
cmGeneratedFileStreamBase::cmGeneratedFileStreamBase(const char* name):
122
 
  m_Name(),
123
 
  m_TempName(),
124
 
  m_CopyIfDifferent(false),
125
 
  m_Okay(false),
126
 
  m_Compress(false)
 
139
  Name(),
 
140
  TempName(),
 
141
  CopyIfDifferent(false),
 
142
  Okay(false),
 
143
  Compress(false),
 
144
  CompressExtraExtension(true)
127
145
{
128
146
  this->Open(name);
129
147
}
138
156
void cmGeneratedFileStreamBase::Open(const char* name)
139
157
{
140
158
  // Save the original name of the file.
141
 
  m_Name = name;
 
159
  this->Name = name;
142
160
 
143
161
  // Create the name of the temporary file.
144
 
  m_TempName = name;
145
 
  m_TempName += ".tmp";
 
162
  this->TempName = name;
 
163
  this->TempName += ".tmp";
146
164
 
147
165
  // Make sure the temporary file that will be used is not present.
148
 
  cmSystemTools::RemoveFile(m_TempName.c_str());
 
166
  cmSystemTools::RemoveFile(this->TempName.c_str());
149
167
 
150
 
  std::string dir = cmSystemTools::GetFilenamePath(m_TempName);
 
168
  std::string dir = cmSystemTools::GetFilenamePath(this->TempName);
151
169
  cmSystemTools::MakeDirectory(dir.c_str());
152
170
}
153
171
 
154
172
//----------------------------------------------------------------------------
155
173
void cmGeneratedFileStreamBase::Close()
156
174
{
157
 
  std::string resname = m_Name;
158
 
  if ( m_Compress )
 
175
  std::string resname = this->Name;
 
176
  if ( this->Compress && this->CompressExtraExtension )
159
177
    {
160
178
    resname += ".gz";
161
179
    }
162
180
 
163
181
  // Only consider replacing the destination file if no error
164
182
  // occurred.
165
 
  if(!m_Name.empty() &&
166
 
    m_Okay &&
167
 
    (!m_CopyIfDifferent ||
168
 
     cmSystemTools::FilesDiffer(m_TempName.c_str(), resname.c_str())))
 
183
  if(!this->Name.empty() &&
 
184
    this->Okay &&
 
185
    (!this->CopyIfDifferent ||
 
186
     cmSystemTools::FilesDiffer(this->TempName.c_str(), resname.c_str())))
169
187
    {
170
188
    // The destination is to be replaced.  Rename the temporary to the
171
189
    // destination atomically.
172
 
    if ( m_Compress )
 
190
    if ( this->Compress )
173
191
      {
174
 
      std::string gzname = m_TempName + ".temp.gz";
175
 
      if ( this->CompressFile(m_TempName.c_str(), gzname.c_str()) )
 
192
      std::string gzname = this->TempName + ".temp.gz";
 
193
      if ( this->CompressFile(this->TempName.c_str(), gzname.c_str()) )
176
194
        {
177
195
        this->RenameFile(gzname.c_str(), resname.c_str());
178
196
        }
180
198
      }
181
199
    else
182
200
      {
183
 
      this->RenameFile(m_TempName.c_str(), resname.c_str());
 
201
      this->RenameFile(this->TempName.c_str(), resname.c_str());
184
202
      }
185
203
    }
186
204
 
187
205
  // Else, the destination was not replaced.
188
206
  //
189
207
  // Always delete the temporary file. We never want it to stay around.
190
 
  cmSystemTools::RemoveFile(m_TempName.c_str());
 
208
  cmSystemTools::RemoveFile(this->TempName.c_str());
191
209
}
192
210
 
193
211
//----------------------------------------------------------------------------
284
302
{
285
303
  if ( !fname )
286
304
    {
287
 
    m_Name = "";
 
305
    this->Name = "";
288
306
    return;
289
307
    }
290
 
  m_Name = fname;
 
308
  this->Name = fname;
291
309
}