Closed Bug 889908 Opened 11 years ago Closed 11 years ago

OS.File.writeAtomic doesn't handle file open error for some writes

Categories

(Toolkit Graveyard :: OS.File, defect)

defect
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED
mozilla25

People

(Reporter: Irving, Assigned: Irving)

Details

Attachments

(1 file, 1 obsolete file)

After the recent sync-write-removal patch, OS.File.writeAtomic no longer reports errors correctly for some file opens.

https://hg.mozilla.org/mozilla-central/file/2cae857c17cb/toolkit/components/osfile/osfile_shared_front.jsm#l362

   359   if (!options.flush) {
   360     // Just write, without any renaming trick
   361     let dest;
   362     try {
   363       dest = OS.File.open(path, {write: true, truncate: true});
   364       return dest.write(buffer, options);
   365     } finally {
   366       dest.close();
   367     }
   368   }

If OS.File.open() fails, the finally() block throws a JS error because dest is undefined.
Attachment #770867 - Flags: review?(dteller)
Comment on attachment 770867 [details] [diff] [review]
Null check the destination file before closing

Review of attachment 770867 [details] [diff] [review]:
-----------------------------------------------------------------

::: toolkit/components/osfile/osfile_shared_front.jsm
@@ +368,2 @@
>      }
>    }

Actually, we could just move the |open| out of the try.
Attachment #770867 - Flags: review?(dteller) → feedback+
Or we could do it this way...
Attachment #770867 - Attachment is obsolete: true
Attachment #770902 - Flags: review?(dteller)
Attachment #770902 - Flags: review?(dteller) → review+
https://hg.mozilla.org/mozilla-central/rev/a828fef4d274
Status: ASSIGNED → RESOLVED
Closed: 11 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla25
Product: Toolkit → Toolkit Graveyard
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: