|
5 | 5 | "log" |
6 | 6 | "os" |
7 | 7 | "path/filepath" |
| 8 | + "strings" |
8 | 9 |
|
9 | 10 | "github.com/BuddhiLW/AutoPDF/configs" |
10 | 11 | "github.com/BuddhiLW/AutoPDF/internal/converter" |
@@ -133,21 +134,26 @@ If no configuration file is provided, it will look for autopdf.yaml in the curre |
133 | 134 | } |
134 | 135 |
|
135 | 136 | // Ensure that the output file exists and isn't empty |
136 | | - if cfg.Output != "" { |
137 | | - // Check if output file exists |
138 | | - fileInfo, err := os.Stat(cfg.Output.String()) |
139 | | - if err != nil { |
140 | | - if os.IsNotExist(err) { |
141 | | - log.Printf("Warning: Output file %s doesn't exist after compilation", cfg.Output.String()) |
142 | | - // Don't create an empty file here - that would hide the real issue |
143 | | - } else { |
144 | | - log.Printf("Error checking output file: %s", err) |
| 137 | + if cfg.Output != "" { |
| 138 | + // Check if output file exists - ensure we check with .pdf extension |
| 139 | + outputPath := cfg.Output.String() |
| 140 | + if !strings.HasSuffix(outputPath, ".pdf") { |
| 141 | + outputPath = outputPath + ".pdf" |
145 | 142 | } |
146 | | - } else if fileInfo.Size() == 0 { |
147 | | - log.Printf("Warning: Output file %s exists but is empty", cfg.Output.String()) |
148 | | - } |
149 | | - |
150 | | - // Use the provided output path |
| 143 | + |
| 144 | + fileInfo, err := os.Stat(outputPath) |
| 145 | + if err != nil { |
| 146 | + if os.IsNotExist(err) { |
| 147 | + log.Printf("Warning: Output file %s doesn't exist after compilation", outputPath) |
| 148 | + // Don't create an empty file here - that would hide the real issue |
| 149 | + } else { |
| 150 | + log.Printf("Error checking output file: %s", err) |
| 151 | + } |
| 152 | + } else if fileInfo.Size() == 0 { |
| 153 | + log.Printf("Warning: Output file %s exists but is empty", outputPath) |
| 154 | + } |
| 155 | + |
| 156 | + // Use the provided output path |
151 | 157 | outputPDF = cfg.Output.String() |
152 | 158 | } |
153 | 159 | fmt.Printf("Successfully built PDF: %s\n", outputPDF) |
|
0 commit comments