From fae622c8b77feebac66a538d76e4211de8bd8eb3 Mon Sep 17 00:00:00 2001 From: Philip McGrath Date: Sun, 24 Jul 2022 21:50:44 -0400 Subject: [PATCH] fix saving `AnyStyle::Dictionary` after `populate!` Some of these fixes are more generally applicable. A more robust solution might find data files using e.g. `Gem.find_files()`. --- lib/anystyle/dictionary/gdbm.rb | 6 ++++++ lib/anystyle/dictionary/marshal.rb | 31 ++++++++++++++++++++++++------ 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/lib/anystyle/dictionary/gdbm.rb b/lib/anystyle/dictionary/gdbm.rb index 754903c..c814df2 100644 --- a/lib/anystyle/dictionary/gdbm.rb +++ b/lib/anystyle/dictionary/gdbm.rb @@ -1,5 +1,6 @@ module AnyStyle require 'gdbm' + require 'fileutils' class Dictionary class GDBM < Dictionary @@ -17,8 +18,13 @@ module AnyStyle def open close + FileUtils.mkdir_p(File.dirname(options[:path])) @db = ::GDBM.new(*options.values_at(:path, :mode, :flags)) self + rescue Errno::EACCES + # GDBM.new tries this if :flags is nil, but not necessarily otherwise + @db = ::GDBM.new(options[:path],options[:mode],::GDBM::READER) + self ensure populate! if empty? end diff --git a/lib/anystyle/dictionary/marshal.rb b/lib/anystyle/dictionary/marshal.rb index 761ca36..b9529d0 100644 --- a/lib/anystyle/dictionary/marshal.rb +++ b/lib/anystyle/dictionary/marshal.rb @@ -1,4 +1,6 @@ module AnyStyle + require 'fileutils' + require 'tempfile' class Dictionary class Marshal < Dictionary @defaults = { @@ -10,17 +12,34 @@ module AnyStyle end def open - if File.exists?(options[:path]) - @db = ::Marshal.load(File.open(options[:path])) - else - @db = {} + File.open(options[:path]) do |file| + @db = ::Marshal.load(file) end self + rescue Errno::ENOENT + @db = {} + self ensure if empty? populate! - if File.writable?(options[:path]) - ::Marshal.dump(db, File.open(options[:path], 'wb')) + tmp = nil + begin + FileUtils.mkdir_p(File.dirname(options[:path])) + tmp = Tempfile.create(File.basename(options[:path]), + File.dirname(options[:path]), + mode: File::Constants::BINARY) + pth = tmp.path() + ::Marshal.dump(db, tmp) + tmp.close() + File.rename(tmp.path, options[:path]) # will overwrite if exists + tmp = nil + rescue SystemCallError => e + warn(e.message) + ensure + if tmp then + tmp.close() + tmp.unlink() + end end end end -- 2.32.0 /pki.scm ("public-keys->acl deduplication"): New test. Ludovic Courtès n. The patch backports the Julia upstream fix. * gnu/packages/julia.scm (julia)[source]: Add patch. * gnu/packages/patches/julia-Use-MPFR-4.2.patch: New file. * gnu/local.mk: Add it. Signed-off-by: Andreas Enge <andreas@enge.fr> Simon Tournier 2023-02-12gnu: julia: Fix build....This follows up on commit 8d8e1438ae5a2e50005b500dacd0a26be540fe69. * gnu/packages/julia.scm (julia)[arguments]: Substitute* libgit2 version. Reported by francismb <francismb@email.de>. Tobias Geerinckx-Rice 2023-02-09gnu: julia: Use SSL_CERT_FILE for SSL certificates....Fixes <https://issues.guix.gnu.org/61121>. * gnu/packages/julia.scm (julia)[arguments]: Add a phase to have Julia use the SSL_CERT_FILE search path. [native-search-paths]: Add SSL_CERT_FILE. Efraim Flashner 2022-12-08gnu: julia: Update to 1.8.3....* gnu/packages/julia.scm (julia): Update to 1.8.3. [source]: Remove one patch. [arguments]: Adjust 'prepare-deps phase to changes in inputs. Remove custom 'use-system-libwhich, 'change-number-of-precompiled-statements, 'symlink-libraries phases. In 'fix-include-and-link-paths phase remove substitution for utf8proc linking and adjust libuv linking. Fix reference to shell in 'replace-default-shell phase. Adjust the 'shared-objects-path phase to changes in the source. Change the 'enable-parallel-tests phase for upstream changes. Adjust the 'adjust-test-suite phase to be more robust. Change the 'disable-broken-tests phase to help the test suite pass. Rename 'symlink-llvm-utf8proc phase to 'symlink-missing-libraries and add two more. Adjust make-flags for changes in shared system libraries. Reorder make-flags to changes in the source. Except for aarch64, use the defaults for choosing to use 64-bit blas. [inputs]: Add libblastrampoline. Replace libgit-1.1 with libgit-1.3, utf8proc-2.7.1 with utf8proc-2.8.0. [native-inputs]: Replace python-2 with python. (libunwind-julia): Update to 1.5.0. [source]: Update patches. * gnu/packages/libevent.scm (libuv-julia): Update to 2.0.0-4.e6f0e49. [arguments]: Also build static library, build position-independent-code. * gnu/packages/llvm.scm (llvm-julia): Update to llvm-13, following upstream's build instructions. * gnu/packages/maths.scm (openlibm): Update to 0.8.1. * gnu/packages/textutils.scm (utf8proc-2.7.1): Update and rename to utf8proc-2.8.0. [native-inputs]: Update unicode to 14.0.0. * gnu/packages/tls.scm (mbedtls-apache): Update to 2.28.0. [source]: Remove snippet. [arguments]: Remove trailing #t from phases. * gnu/packages/patches/julia-allow-parallel-build.patch, (julia-patch): Update version string to 1.8.2. gnu/packages/patches/libunwind-julia-fix-GCC10-fno-common.patch: Remove files. * gnu/local.mk (dist_patch_DATA): Remove them. Co-authored-by: Akira Kyle <akira@akirakyle.com> Efraim Flashner 2022-12-08gnu: julia: Make libquadmath optional....* gnu/packages/julia.scm (julia)[arguments]: Replace custom phase removing libquadmath requirement for aarch64-linux with phase to make libquadmath support optional. Efraim Flashner 2022-12-08gnu: julia: Also skip tests when cross-compiling....* gnu/packages/julia.scm (julia)[arguments]: Don't run the test suite when cross-compiling. Efraim Flashner