~ubuntu-branches/ubuntu/precise/vorbis-tools/precise

« back to all changes in this revision

Viewing changes to debian/patches/upstream_r9935-dont_clobber_file_on_error.diff

  • Committer: Bazaar Package Importer
  • Author(s): Clint Adams
  • Date: 2008-06-09 21:04:10 UTC
  • mfrom: (4.1.10 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080609210410-h0dkh8f8riyiiv4m
Tags: 1.2.0-5
* Bump to Standards-Version 3.8.0. 
* Refresh upstream_r14957-ogg123_stop_decode_on_closed_buffer.diff and
  upstream_r14982-ogg123_man_page_http_only.diff to -p ab.
  closes: #484961.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
Index: trunk/vorbis-tools/vorbiscomment/vcomment.c
2
 
===================================================================
3
 
--- trunk/vorbis-tools/vorbiscomment/vcomment.c (revision 9393)
4
 
+++ trunk/vorbis-tools/vorbiscomment/vcomment.c (revision 9935)
5
 
@@ -64,5 +64,5 @@
6
 
 void parse_options(int argc, char *argv[], param_t *param);
7
 
 void open_files(param_t *p);
8
 
-void close_files(param_t *p);
9
 
+void close_files(param_t *p, int output_written);
10
 
 
11
 
 
12
 
@@ -108,5 +108,5 @@
13
 
                        fprintf(stderr, _("Failed to open file as vorbis: %s\n"), 
14
 
                                        vcedit_error(state));
15
 
-            close_files(param);
16
 
+            close_files(param, 0);
17
 
             free_param(param);
18
 
             vcedit_clear(state);
19
 
@@ -121,5 +121,5 @@
20
 
                vcedit_clear(state);
21
 
 
22
 
-               close_files(param);
23
 
+               close_files(param, 0);
24
 
         free_param(param);
25
 
                return 0;               
26
 
@@ -134,5 +134,5 @@
27
 
                        fprintf(stderr, _("Failed to open file as vorbis: %s\n"), 
28
 
                                        vcedit_error(state));
29
 
-            close_files(param);
30
 
+            close_files(param, 0);
31
 
             free_param(param);
32
 
             vcedit_clear(state);
33
 
@@ -175,5 +175,5 @@
34
 
                        fprintf(stderr, _("Failed to write comments to output file: %s\n"), 
35
 
                                        vcedit_error(state));
36
 
-            close_files(param);
37
 
+            close_files(param, 0);
38
 
             free_param(param);
39
 
             vcedit_clear(state);
40
 
@@ -184,5 +184,5 @@
41
 
                vcedit_clear(state);
42
 
                
43
 
-               close_files(param);
44
 
+               close_files(param, 1);
45
 
         free_param(param);
46
 
                return 0;
47
 
@@ -528,22 +528,30 @@
48
 
 ***********/
49
 
 
50
 
-void close_files(param_t *p)
51
 
-{
52
 
-       if (p->in != NULL && p->in != stdin) fclose(p->in);
53
 
-       if (p->out != NULL && p->out != stdout) fclose(p->out);
54
 
-       if (p->com != NULL && p->com != stdout && p->com != stdin) fclose(p->com);
55
 
-
56
 
-       if(p->tempoutfile) {
57
 
-        /* Some platforms fail to rename a file if the new name already exists,
58
 
-         * so we need to remove, then rename. How stupid.
59
 
-         */
60
 
-               if(rename(p->outfilename, p->infilename)) {
61
 
-            if(remove(p->infilename))
62
 
-                fprintf(stderr, _("Error removing old file %s\n"), p->infilename);
63
 
-            else if(rename(p->outfilename, p->infilename)) 
64
 
-                fprintf(stderr, _("Error renaming %s to %s\n"), p->outfilename, 
65
 
-                        p->infilename);
66
 
-        }
67
 
+void close_files(param_t *p, int output_written)
68
 
+{
69
 
+  if (p->in != NULL && p->in != stdin) fclose(p->in);
70
 
+  if (p->out != NULL && p->out != stdout) fclose(p->out);
71
 
+  if (p->com != NULL && p->com != stdout && p->com != stdin) fclose(p->com);
72
 
+
73
 
+  if(p->tempoutfile) {
74
 
+    if(output_written) {
75
 
+      /* Some platforms fail to rename a file if the new name already 
76
 
+       * exists, so we need to remove, then rename. How stupid.
77
 
+       */
78
 
+      if(rename(p->outfilename, p->infilename)) {
79
 
+        if(remove(p->infilename))
80
 
+          fprintf(stderr, _("Error removing old file %s\n"), p->infilename);
81
 
+        else if(rename(p->outfilename, p->infilename)) 
82
 
+          fprintf(stderr, _("Error renaming %s to %s\n"), p->outfilename, 
83
 
+                  p->infilename);
84
 
+      }
85
 
     }
86
 
-}
87
 
-
88
 
+    else {
89
 
+      if(remove(p->outfilename)) {
90
 
+        fprintf(stderr, _("Error removing erroneous temporary file %s\n"), 
91
 
+                    p->outfilename);
92
 
+      }
93
 
+    }
94
 
+  }
95
 
+}
96
 
+