From 898e1db3edf44b518cef3c83db63fd8df23dc337 Mon Sep 17 00:00:00 2001 From: Marian Bajan Date: Wed, 12 Jun 2024 11:33:41 +0000 Subject: [PATCH 1/3] created temporary folder only if vips.Startup() is called; also initialized the ICCProfilePaths in initializeICCProfiles() --- vips/govips.go | 2 ++ vips/icc_profiles.go | 27 ++++++++++++++++++++------- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/vips/govips.go b/vips/govips.go index 6969b62a..bbb66258 100644 --- a/vips/govips.go +++ b/vips/govips.go @@ -67,6 +67,8 @@ func Startup(config *Config) { runtime.LockOSThread() defer runtime.UnlockOSThread() + createTemporaryDirectoryOrPanic() + if running { govipsLog("govips", LogLevelInfo, "warning libvips already started") return diff --git a/vips/icc_profiles.go b/vips/icc_profiles.go index f10c4292..d6b880f7 100644 --- a/vips/icc_profiles.go +++ b/vips/icc_profiles.go @@ -644,14 +644,24 @@ var ( 0x00, 0x20, 0x63, 0xcf, 0x8f, 0xf0, 0x65, 0x87, 0x4e, 0xf6, 0x00, 0x00, } - temporaryDirectory = temporaryDirectoryOrPanic() - SRGBV2MicroICCProfilePath = filepath.Join(temporaryDirectory, "srgb_v2_micro.icc") - SGrayV2MicroICCProfilePath = filepath.Join(temporaryDirectory, "sgray_v2_micro.icc") - SRGBIEC6196621ICCProfilePath = filepath.Join(temporaryDirectory, "srgb_iec61966_2_1.icc") - GenericGrayGamma22ICCProfilePath = filepath.Join(temporaryDirectory, "generic_gray_gamma_2_2.icc") + temporaryDirectory string + SRGBV2MicroICCProfilePath string + SGrayV2MicroICCProfilePath string + SRGBIEC6196621ICCProfilePath string + GenericGrayGamma22ICCProfilePath string ) func initializeICCProfiles() { + + if temporaryDirectory != "" { + createTemporaryDirectoryOrPanic() + } + + SRGBV2MicroICCProfilePath = filepath.Join(temporaryDirectory, "srgb_v2_micro.icc") + SGrayV2MicroICCProfilePath = filepath.Join(temporaryDirectory, "sgray_v2_micro.icc") + SRGBIEC6196621ICCProfilePath = filepath.Join(temporaryDirectory, "srgb_iec61966_2_1.icc") + GenericGrayGamma22ICCProfilePath = filepath.Join(temporaryDirectory, "generic_gray_gamma_2_2.icc") + storeIccProfile(SRGBV2MicroICCProfilePath, sRGBV2MicroICCProfile) storeIccProfile(SGrayV2MicroICCProfilePath, sGrayV2MicroICCProfile) storeIccProfile(SRGBIEC6196621ICCProfilePath, sRGBIEC6196621ICCProfile) @@ -665,8 +675,11 @@ func storeIccProfile(path string, data []byte) { } } -func temporaryDirectoryOrPanic() string { - temporaryDirectory, err := os.MkdirTemp("", "govips-") +func createTemporaryDirectoryOrPanic() string { + + tmpDir, err := os.MkdirTemp("", "govips-") + temporaryDirectory = tmpDir // assign to global variable + if err != nil { panic(fmt.Sprintf("Couldn't create temporary directory: %v", err.Error())) } From b68a66d4f7e5c9bf2fd61b0a4ab3ca5baa1150ca Mon Sep 17 00:00:00 2001 From: Marian Bajan Date: Wed, 12 Jun 2024 12:39:17 +0000 Subject: [PATCH 2/3] fixed if statement --- vips/icc_profiles.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vips/icc_profiles.go b/vips/icc_profiles.go index d6b880f7..7c80b90a 100644 --- a/vips/icc_profiles.go +++ b/vips/icc_profiles.go @@ -653,7 +653,7 @@ var ( func initializeICCProfiles() { - if temporaryDirectory != "" { + if temporaryDirectory == "" { createTemporaryDirectoryOrPanic() } From 2a223df8d8990b59ba4fb47c9f99d207bed0243b Mon Sep 17 00:00:00 2001 From: Marian Bajan Date: Wed, 12 Jun 2024 12:50:03 +0000 Subject: [PATCH 3/3] moved createTemporaryDirectoryOrPanic() call --- vips/govips.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/vips/govips.go b/vips/govips.go index bbb66258..1cf95561 100644 --- a/vips/govips.go +++ b/vips/govips.go @@ -67,8 +67,6 @@ func Startup(config *Config) { runtime.LockOSThread() defer runtime.UnlockOSThread() - createTemporaryDirectoryOrPanic() - if running { govipsLog("govips", LogLevelInfo, "warning libvips already started") return @@ -98,6 +96,7 @@ func Startup(config *Config) { panic(fmt.Sprintf("Failed to start vips code=%v", err)) } + createTemporaryDirectoryOrPanic() initializeICCProfiles() running = true