Skip to content

Commit

Permalink
Handle legacy configuration format better
Browse files Browse the repository at this point in the history
  • Loading branch information
joeyates committed Nov 15, 2023
1 parent 6b0d6fd commit fa59142
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 11 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## 14.4.0 - 2023-11-15

### Changed

* Always check whether the configuration file has folders
listed as an Array of Hashes, and convert to the newer,
simpler, structure. See #184

## 14.3.0 - 2023-11-03

### Added
Expand Down
19 changes: 11 additions & 8 deletions lib/imap/backup/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,27 +122,30 @@ def data
else
DEFAULT_STRATEGY
end
if data[:version] == VERSION_2_1
dehashify_folders(data)
else
data
end
dehashify_folders(data)
else
{accounts: [], download_strategy: DEFAULT_STRATEGY}
end
end

def dehashify_folders(data)
data[:version] = VERSION

data[:accounts].each do |account|
next if !account.key?(:folders)

folders = account[:folders]
names = folders.map { |f| f[:name] }
names = folders.map do |f|
case f
when Hash
f[:name]
else
f
end
end
account[:folders] = names
end

data[:version] = VERSION

data
end

Expand Down
2 changes: 1 addition & 1 deletion lib/imap/backup/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Imap; end

module Imap::Backup
MAJOR = 14
MINOR = 3
MINOR = 4
REVISION = 0
PRE = nil
VERSION = [MAJOR, MINOR, REVISION, PRE].compact.map(&:to_s).join(".")
Expand Down
4 changes: 2 additions & 2 deletions spec/unit/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,10 @@ module Imap::Backup
end
end

context "when a version 2.1 file is present" do
context "when a folders are stored as Hashes" do
let(:file) { instance_double(File, write: nil) }
let(:configuration) do
{version: "2.1", accounts: [{username: "account", folders: [{name: "foo"}]}]}.to_json
{accounts: [{username: "account", folders: [{name: "foo"}]}]}.to_json
end

before do
Expand Down

0 comments on commit fa59142

Please sign in to comment.