begin
From := Open_Read (Name, Binary);
- To := Create_File (To_Name, Binary);
+
+ -- Do not clobber destination file if source file could not be opened
+
+ if From /= Invalid_FD then
+ To := Create_File (To_Name, Binary);
+ end if;
+
Copy (From, To);
-- Copy attributes
if Is_Regular_File (Pathname) then
-- Append mode and destination file exists, append data at the
- -- end of Pathname.
+ -- end of Pathname. But if we fail to open source file, do not
+ -- touch destination file at all.
From := Open_Read (Name, Binary);
- To := Open_Read_Write (Pathname, Binary);
+ if From /= Invalid_FD then
+ To := Open_Read_Write (Pathname, Binary);
+ end if;
+
Lseek (To, 0, Seek_End);
Copy (From, To);