Skip to content

Commit 58a1e27

Browse files
committed
Fix #174
1 parent ed59dc3 commit 58a1e27

2 files changed

Lines changed: 31 additions & 12 deletions

File tree

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ Get the latest binary [here](https://github.com/pdfcpu/pdfcpu/releases).
9595

9696
### Using GOPATH
9797

98-
Required go version for building: go1.13 and up
98+
Required go version for building: go1.14 and up
9999

100100
```
101101
go get github.com/pdfcpu/pdfcpu/cmd/...
@@ -110,15 +110,16 @@ pdfcpu version
110110
git clone https://github.com/pdfcpu/pdfcpu
111111
cd pdfcpu/cmd/pdfcpu
112112
go install
113-
pdfcpu ve
113+
pdfcpu version
114114
```
115115

116116
### Using Homebrew (macOS)
117117
```
118118
brew install pdfcpu
119+
pdfcpu version
119120
```
120121

121-
### Using Docker
122+
### Run in a Docker container
122123

123124
```
124125
docker build -t pdfcpu .

pkg/api/api.go

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,11 @@ func SplitFile(inFile, outDir string, span int, conf *pdf.Configuration) error {
775775
log.CLI.Printf("splitting %s to %s/...\n", inFile, outDir)
776776

777777
defer func() {
778-
f.Close()
778+
if err != nil {
779+
f.Close()
780+
return
781+
}
782+
err = f.Close()
779783
}()
780784

781785
return Split(f, outDir, filepath.Base(inFile), span, conf)
@@ -1388,9 +1392,7 @@ func ImportImagesFile(imgFiles []string, outFile string, imp *pdf.Import, conf *
13881392
os.Remove(tmpFile)
13891393
}
13901394
for _, f := range rc {
1391-
if err := f.Close(); err != nil {
1392-
return
1393-
}
1395+
f.Close()
13941396
}
13951397
return
13961398
}
@@ -1405,6 +1407,11 @@ func ImportImagesFile(imgFiles []string, outFile string, imp *pdf.Import, conf *
14051407
return
14061408
}
14071409
}
1410+
for _, f := range rc {
1411+
if err := f.Close(); err != nil {
1412+
return
1413+
}
1414+
}
14081415
}()
14091416

14101417
return ImportImages(rs, f2, rr, imp, conf)
@@ -1651,9 +1658,19 @@ func MergeCreateFile(inFiles []string, outFile string, conf *pdf.Configuration)
16511658
return err
16521659
}
16531660
defer func() {
1654-
f.Close()
1655-
for _, f := range ff {
1661+
if err != nil {
16561662
f.Close()
1663+
for _, f := range ff {
1664+
f.Close()
1665+
}
1666+
}
1667+
if err = f.Close(); err != nil {
1668+
return
1669+
}
1670+
for _, f := range ff {
1671+
if err = f.Close(); err != nil {
1672+
return
1673+
}
16571674
}
16581675
}()
16591676

@@ -1703,7 +1720,6 @@ func MergeAppendFile(inFiles []string, outFile string, conf *pdf.Configuration)
17031720
if err != nil {
17041721
f2.Close()
17051722
if f1 != nil {
1706-
f1.Close()
17071723
os.Remove(tmpFile)
17081724
}
17091725
for _, f := range ff {
@@ -1715,10 +1731,12 @@ func MergeAppendFile(inFiles []string, outFile string, conf *pdf.Configuration)
17151731
return
17161732
}
17171733
if f1 != nil {
1718-
if err = f1.Close(); err != nil {
1734+
if err = os.Rename(tmpFile, outFile); err != nil {
17191735
return
17201736
}
1721-
if err = os.Rename(tmpFile, outFile); err != nil {
1737+
}
1738+
for _, f := range ff {
1739+
if err = f.Close(); err != nil {
17221740
return
17231741
}
17241742
}

0 commit comments

Comments
 (0)