Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 617818
Collapse All | Expand All

(-)file_not_specified_in_diff (-37 / +57 lines)
Line  Link Here
0
-- b/src/tags/vcedit.c
0
++ a/src/tags/vcedit.c
Lines 35-40 Link Here
35
struct _EtOggState
35
struct _EtOggState
36
{
36
{
37
    /*< private >*/
37
    /*< private >*/
38
    GFileInputStream *in;
38
#ifdef ENABLE_SPEEX
39
#ifdef ENABLE_SPEEX
39
    SpeexHeader *si;
40
    SpeexHeader *si;
40
#endif
41
#endif
Lines 125-130 Link Here
125
    }
126
    }
126
#endif /* ENABLE_OPUS */
127
#endif /* ENABLE_OPUS */
127
128
129
    if (state->in)
130
    {
131
        g_object_unref (state->in);
132
    }
133
128
    memset (state, 0, sizeof (*state));
134
    memset (state, 0, sizeof (*state));
129
}
135
}
130
136
Lines 239-245 Link Here
239
245
240
static gboolean
246
static gboolean
241
_fetch_next_packet (EtOggState *s,
247
_fetch_next_packet (EtOggState *s,
242
                    GInputStream *istream,
243
                    ogg_packet *p,
248
                    ogg_packet *p,
244
                    ogg_page *page,
249
                    ogg_page *page,
245
                    GError **error)
250
                    GError **error)
Lines 269-276 Link Here
269
        while (ogg_sync_pageout (s->oy, page) <= 0)
274
        while (ogg_sync_pageout (s->oy, page) <= 0)
270
        {
275
        {
271
            buffer = ogg_sync_buffer (s->oy, CHUNKSIZE);
276
            buffer = ogg_sync_buffer (s->oy, CHUNKSIZE);
272
            bytes = g_input_stream_read (istream, buffer, CHUNKSIZE, NULL,
277
            bytes = g_input_stream_read (G_INPUT_STREAM (s->in), buffer,
273
                                         error);
278
                                         CHUNKSIZE, NULL, error);
274
            ogg_sync_wrote (s->oy, bytes);
279
            ogg_sync_wrote (s->oy, bytes);
275
280
276
            if(bytes == 0)
281
            if(bytes == 0)
Lines 303-309 Link Here
303
308
304
        g_assert (error == NULL || *error == NULL);
309
        g_assert (error == NULL || *error == NULL);
305
        ogg_stream_pagein (s->os, page);
310
        ogg_stream_pagein (s->os, page);
306
        return _fetch_next_packet (s, istream, p, page, error);
311
        return _fetch_next_packet (s, p, page, error);
307
    }
312
    }
308
}
313
}
309
314
Lines 402-414 Link Here
402
        return FALSE;
407
        return FALSE;
403
    }
408
    }
404
409
410
    state->in = istream;
405
    state->oy = g_slice_new (ogg_sync_state);
411
    state->oy = g_slice_new (ogg_sync_state);
406
    ogg_sync_init (state->oy);
412
    ogg_sync_init (state->oy);
407
413
408
    while(1)
414
    while(1)
409
    {
415
    {
410
        buffer = ogg_sync_buffer (state->oy, CHUNKSIZE);
416
        buffer = ogg_sync_buffer (state->oy, CHUNKSIZE);
411
        bytes = g_input_stream_read (G_INPUT_STREAM (istream), buffer,
417
        bytes = g_input_stream_read (G_INPUT_STREAM (state->in), buffer,
412
                                     CHUNKSIZE, NULL, error);
418
                                     CHUNKSIZE, NULL, error);
413
        if (bytes == -1)
419
        if (bytes == -1)
414
        {
420
        {
Lines 648-654 Link Here
648
        }
654
        }
649
655
650
        buffer = ogg_sync_buffer (state->oy, CHUNKSIZE);
656
        buffer = ogg_sync_buffer (state->oy, CHUNKSIZE);
651
        bytes = g_input_stream_read (G_INPUT_STREAM (istream), buffer,
657
        bytes = g_input_stream_read (G_INPUT_STREAM (state->in), buffer,
652
                                     CHUNKSIZE, NULL, error);
658
                                     CHUNKSIZE, NULL, error);
653
659
654
        if (bytes == -1)
660
        if (bytes == -1)
Lines 670-683 Link Here
670
676
671
    /* Headers are done! */
677
    /* Headers are done! */
672
    g_assert (error == NULL || *error == NULL);
678
    g_assert (error == NULL || *error == NULL);
673
    /* TODO: Handle error during stream close. */
674
    g_object_unref (istream);
675
679
676
    return TRUE;
680
    return TRUE;
677
681
678
err:
682
err:
679
    g_assert (error == NULL || *error != NULL);
683
    g_assert (error == NULL || *error != NULL);
680
    g_object_unref (istream);
681
    vcedit_clear_internals (state);
684
    vcedit_clear_internals (state);
682
    return FALSE;
685
    return FALSE;
683
}
686
}
Lines 699-705 Link Here
699
    char *buffer;
702
    char *buffer;
700
    int bytes;
703
    int bytes;
701
    int needflush = 0, needout = 0;
704
    int needflush = 0, needout = 0;
702
    GFileInputStream *istream;
703
    GOutputStream *ostream;
705
    GOutputStream *ostream;
704
    gchar *buf;
706
    gchar *buf;
705
    gsize size;
707
    gsize size;
Lines 707-728 Link Here
707
709
708
    g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
710
    g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
709
711
710
    istream = g_file_read (file, NULL, error);
712
    fileinfo = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_SIZE,
711
713
                                  G_FILE_QUERY_INFO_NONE, NULL, error);
712
    if (!istream)
713
    {
714
        g_assert (error == NULL || *error != NULL);
715
        return FALSE;
716
    }
717
718
    fileinfo = g_file_input_stream_query_info (istream,
719
                                               G_FILE_ATTRIBUTE_STANDARD_SIZE,
720
                                               NULL, error);
721
722
    if (!fileinfo)
714
    if (!fileinfo)
723
    {
715
    {
724
        g_assert (error == NULL || *error != NULL);
716
        g_assert (error == NULL || *error != NULL);
725
        g_object_unref (istream);
726
        return FALSE;
717
        return FALSE;
727
    }
718
    }
728
719
Lines 783-790 Link Here
783
        }
774
        }
784
    }
775
    }
785
776
786
    while (_fetch_next_packet (state, G_INPUT_STREAM (istream), &op, &ogin,
777
    while (_fetch_next_packet (state, &op, &ogin, error))
787
                               error))
788
    {
778
    {
789
        if (needflush)
779
        if (needflush)
790
        {
780
        {
Lines 960-966 Link Here
960
    {
950
    {
961
        /* We copy the rest of the stream (other logical streams)
951
        /* We copy the rest of the stream (other logical streams)
962
         * through, a page at a time. */
952
         * through, a page at a time. */
963
        while (1)
953
        while(1)
964
        {
954
        {
965
            result = ogg_sync_pageout (state->oy, &ogout);
955
            result = ogg_sync_pageout (state->oy, &ogout);
966
956
Lines 999-1005 Link Here
999
989
1000
        buffer = ogg_sync_buffer (state->oy, CHUNKSIZE);
990
        buffer = ogg_sync_buffer (state->oy, CHUNKSIZE);
1001
991
1002
        bytes = g_input_stream_read (G_INPUT_STREAM (istream), buffer,
992
        bytes = g_input_stream_read (G_INPUT_STREAM (state->in), buffer,
1003
                                     CHUNKSIZE, NULL, error);
993
                                     CHUNKSIZE, NULL, error);
1004
994
1005
        if (bytes == -1)
995
        if (bytes == -1)
Lines 1017-1035 Link Here
1017
        }
1007
        }
1018
    }
1008
    }
1019
1009
1010
1020
cleanup:
1011
cleanup:
1021
    ogg_stream_clear (&streamout);
1012
    ogg_stream_clear (&streamout);
1022
    ogg_packet_clear (&header_comments);
1013
    ogg_packet_clear (&header_comments);
1023
1014
1024
    if (!g_input_stream_close (G_INPUT_STREAM (istream), NULL, error))
1025
    {
1026
        /* Ignore the _close() failure, and try the write anyway. */
1027
        g_warning ("Error closing Ogg file for reading: %s",
1028
                   (*error)->message);
1029
        g_clear_error (error);
1030
    }
1031
1032
    g_object_unref (istream);
1033
    g_free (state->mainbuf);
1015
    g_free (state->mainbuf);
1034
    g_free (state->bookbuf);
1016
    g_free (state->bookbuf);
1035
    state->mainbuf = state->bookbuf = NULL;
1017
    state->mainbuf = state->bookbuf = NULL;
Lines 1063-1075 Link Here
1063
    buf = g_memory_output_stream_steal_data (G_MEMORY_OUTPUT_STREAM (ostream));
1045
    buf = g_memory_output_stream_steal_data (G_MEMORY_OUTPUT_STREAM (ostream));
1064
    size = g_memory_output_stream_get_data_size (G_MEMORY_OUTPUT_STREAM (ostream));
1046
    size = g_memory_output_stream_get_data_size (G_MEMORY_OUTPUT_STREAM (ostream));
1065
1047
1048
    /* At least on Windows, writing to a file with an open-for-reading stream
1049
     * fails, so close the input stream before writing to the file. */
1050
    if (!g_input_stream_close (G_INPUT_STREAM (state->in), NULL, error))
1051
    {
1052
        /* Ignore the _close() failure, and try the write anyway. */
1053
        g_warning ("Error closing Ogg file for reading: %s",
1054
                   (*error)->message);
1055
        g_clear_error (error);
1056
    }
1057
1058
    g_object_unref (state->in);
1059
    state->in = NULL;
1060
1066
    /* Write the in-memory data back out to the original file. */
1061
    /* Write the in-memory data back out to the original file. */
1067
    if (!g_file_replace_contents (file, buf, size, NULL, FALSE,
1062
    if (!g_file_replace_contents (file, buf, size, NULL, FALSE,
1068
                                  G_FILE_CREATE_NONE, NULL, NULL, error))
1063
                                  G_FILE_CREATE_NONE, NULL, NULL, error))
1069
    {
1064
    {
1065
        GError *tmp_error = NULL;
1066
1070
        g_object_unref (ostream);
1067
        g_object_unref (ostream);
1071
        g_free (buf);
1068
        g_free (buf);
1072
1069
1070
        /* Re-open the file for reading, to keep the internal state
1071
         * consistent. */
1072
        state->in = g_file_read (file, NULL, &tmp_error);
1073
1074
        if (!state->in)
1075
        {
1076
            g_warning ("Error opening Ogg file for reading after write failure: %s",
1077
                       tmp_error->message);
1078
            g_clear_error (&tmp_error);
1079
            g_assert (error == NULL || *error != NULL);
1080
            return FALSE;
1081
        }
1082
1073
        g_assert (error == NULL || *error != NULL);
1083
        g_assert (error == NULL || *error != NULL);
1074
        return FALSE;
1084
        return FALSE;
1075
    }
1085
    }
Lines 1077-1082 Link Here
1077
    g_free (buf);
1087
    g_free (buf);
1078
    g_object_unref (ostream);
1088
    g_object_unref (ostream);
1079
1089
1090
    /* Re-open the file, now that the write has completed. */
1091
    state->in = g_file_read (file, NULL, error);
1092
1093
    if (!state->in)
1094
    {
1095
        g_assert (error == NULL || *error != NULL);
1096
        return FALSE;
1097
    }
1098
1099
1080
    return TRUE;
1100
    return TRUE;
1081
}
1101
}

Return to bug 617818