Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 94d27a80 authored by Tomasz Mikolajewski's avatar Tomasz Mikolajewski Committed by Android (Google) Code Review
Browse files

Merge "Do not close streams prematurely."

parents a56c9b0c e1e3ae86
Loading
Loading
Loading
Loading
+48 −34
Original line number Diff line number Diff line
@@ -199,6 +199,9 @@ public class Archive implements Closeable {
     *
     * If the file descriptor is not seekable, then a snapshot will be created.
     *
     * This method takes ownership for the passed descriptor. The caller must
     * not close it.
     *
     * @param context Context of the provider.
     * @param descriptor File descriptor for the archive's contents.
     * @param archiveUri Uri of the archive document.
@@ -208,8 +211,12 @@ public class Archive implements Closeable {
            Context context, ParcelFileDescriptor descriptor, Uri archiveUri,
            @Nullable Uri notificationUri)
            throws IOException {
        FileDescriptor fd = null;
        try {
            if (canSeek(descriptor)) {
            return new Archive(context, null, descriptor.getFileDescriptor(), archiveUri,
                fd = new FileDescriptor();
                fd.setInt$(descriptor.detachFd());
                return new Archive(context, null, fd, archiveUri,
                        notificationUri);
            }

@@ -246,6 +253,13 @@ public class Archive implements Closeable {
                    snapshotFile.delete();
                }
            }
        } catch (Exception e) {
            // Since the method takes ownership of the passed descriptor, close it
            // on exception.
            IoUtils.closeQuietly(descriptor);
            IoUtils.closeQuietly(fd);
            throw e;
        }
    }

    /**