Skip to content

Commit 0529702

Browse files
committed
properly clean up after exiftool perl5.18 processes
1 parent 653b7f6 commit 0529702

File tree

2 files changed

+29
-11
lines changed

2 files changed

+29
-11
lines changed

src/common/add_files.js

+28-10
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,30 @@ async function addFiles({ files }) {
1212
}
1313
}
1414

15+
function newExifToolProcess() {
16+
return new exiftool.ExiftoolProcess(exiftoolBinPath);
17+
}
18+
1519
async function showExifBeforeClean({ trNode, filePath }) {
1620
const tdBeforeNode = trNode.querySelector("td:nth-child(2)");
17-
const exifData = await getExif({ filePath: filePath });
21+
const ep = newExifToolProcess();
22+
const exifData = await getExif({ ep: ep, filePath: filePath }).then(val => {
23+
ep.close();
24+
return val;
25+
});
1826

1927
updateRowWithExif({ tdNode: tdBeforeNode, exifData: exifData });
2028
}
2129

2230
async function showExifAfterClean({ trNode, filePath }) {
2331
const tdAfterNode = trNode.querySelector("td:nth-child(3)");
24-
const newExifData = await getExif({ filePath: filePath });
32+
const ep = newExifToolProcess();
33+
const newExifData = await getExif({ ep: ep, filePath: filePath }).then(
34+
val => {
35+
ep.close();
36+
return val;
37+
}
38+
);
2539

2640
updateRowWithExif({ tdNode: tdAfterNode, exifData: newExifData });
2741
return Promise.resolve();
@@ -38,7 +52,11 @@ async function addFile({ file }) {
3852
return updateRowWithCleanerSpinner({ trNode: trNode });
3953
})
4054
.then(() => {
41-
return removeExif({ filePath: filePath });
55+
const ep = newExifToolProcess();
56+
return removeExif({ ep: ep, filePath: filePath }).then(val => {
57+
ep.close();
58+
return val;
59+
});
4260
})
4361
.then(() => {
4462
return showExifAfterClean({ trNode: trNode, filePath: filePath });
@@ -68,7 +86,9 @@ function cleanExifData(exifHash) {
6886
//
6987
// Opening and Closing
7088
//
71-
// After creating an instance of ExiftoolProcess, it must be opened. When finished working with it, it should be closed, when -stay_open False will be written to its stdin to exit the process.
89+
// After creating an instance of ExiftoolProcess, it must be opened.
90+
// When finished working with it, it should be closed,
91+
// when -stay_open False will be written to its stdin to exit the process.
7292
//
7393
// const exiftool = require('node-exiftool')
7494
// const ep = new exiftool.ExiftoolProcess()
@@ -79,8 +99,7 @@ function cleanExifData(exifHash) {
7999
// .then(() => ep.close())
80100
// .then(() => console.log('Closed exiftool'))
81101
// .catch(console.error)
82-
async function removeExif({ filePath }) {
83-
const ep = new exiftool.ExiftoolProcess(exiftoolBinPath);
102+
async function removeExif({ ep, filePath }) {
84103
const exifData = ep
85104
.open()
86105
// .then((pid) => console.log('Started exiftool process %s', pid))
@@ -89,13 +108,12 @@ async function removeExif({ filePath }) {
89108
})
90109
.catch(console.error);
91110

92-
return Promise.resolve(exifData);
111+
return exifData;
93112
}
94113

95114
// Read the exif data using the exiftool bin.
96115
// This should also have the perl processes cleaned up after.
97-
async function getExif({ filePath }) {
98-
const ep = new exiftool.ExiftoolProcess(exiftoolBinPath);
116+
async function getExif({ ep, filePath }) {
99117
const exifData = ep
100118
.open()
101119
// .then((pid) => console.log('Started exiftool process %s', pid))
@@ -119,7 +137,7 @@ async function getExif({ filePath }) {
119137
})
120138
.catch(console.error);
121139

122-
return Promise.resolve(exifData);
140+
return exifData;
123141
}
124142

125143
module.exports = {

src/main/init.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const unhandled = require("electron-unhandled");
33
const debug = require("electron-debug");
44
const contextMenu = require("electron-context-menu");
55
const packageJson = require("../../package.json");
6-
const { setupAutoUpdate } = require("./auto_update");
6+
// const { setupAutoUpdate } = require("./auto_update");
77
const { setupApp } = require("./app_setup");
88

99
function setupErrorHandling() {

0 commit comments

Comments
 (0)