flist 0.1.30 → 0.1.33
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/main.yml +31 -0
- data/.gitignore +5 -0
- data/.rubocop.yml +12 -0
- data/.rubocop_todo.yml +129 -0
- data/Gemfile +22 -0
- data/Rakefile +50 -3
- data/SECURITY.md +21 -0
- data/bin/console +4 -3
- data/bin/setup +2 -0
- data/config/.gitkeep +0 -0
- data/config/config.yml +14 -0
- data/config/config_sample.yml +15 -0
- data/config/config_yml.sample +15 -0
- data/config/db_scheme.yml +71 -0
- data/config/db_scheme.yml.sample +48 -0
- data/config/dbsetup.rb +56 -0
- data/config/opts.rb +9 -0
- data/config/opts.rb.sample +7 -0
- data/config/setting.yml +2 -0
- data/config/sqlite3.yml +26 -0
- data/config/tmp/db_scheme.yml +71 -0
- data/db/migrate/010_create_countdatetime.rb +11 -0
- data/db/migrate/020_create_flistz.rb +22 -0
- data/db/migrate/030_create_invalidflistz.rb +13 -0
- data/db/migrate/040_create_currentflistz.rb +15 -0
- data/db/migrate/050_create_dirz.rb +12 -0
- data/db/migrate/060_create_invaliddirz.rb +13 -0
- data/db/migrate/070_create_currentdirz.rb +15 -0
- data/exe/flist +80 -27
- data/flist.gemspec +33 -20
- data/lib/dbacrecord.rb +36 -0
- data/lib/flist/cli.rb +49 -0
- data/lib/flist/config.rb +16 -0
- data/lib/flist/csvx.rb +29 -0
- data/lib/flist/dbutil/dbmgr.rb +25 -24
- data/lib/flist/dbutil/dirzmgr.rb +75 -12
- data/lib/flist/dbutil/flistzmgr.rb +81 -34
- data/lib/flist/dbutil.rb +4 -4
- data/lib/flist/flist/filelist.rb +219 -168
- data/lib/flist/flist.rb +282 -101
- data/lib/flist/version.rb +3 -1
- data/lib/flist.rb +51 -5
- data/lib/template/config_yml.erb +15 -0
- metadata +128 -33
- data/exe/makemigrate +0 -52
- data/lib/flist/flist/store.rb +0 -79
@@ -0,0 +1,22 @@
|
|
1
|
+
class CreateFlistz < ActiveRecord::Migration[6.0]
|
2
|
+
def self.up
|
3
|
+
create_table :Flistzs do |t|
|
4
|
+
t.column :dir_id, :integer, :null => false
|
5
|
+
t.column :level, :integer, :null => false
|
6
|
+
t.column :kind, :string, :null => false
|
7
|
+
t.column :repo, :string, :null => false
|
8
|
+
t.column :path, :string, :null => false
|
9
|
+
t.column :project, :string, :null => false
|
10
|
+
t.column :desc, :string, :null => true
|
11
|
+
t.column :comment, :string, :null => true
|
12
|
+
t.column :atime, :datetime, :null => false
|
13
|
+
t.column :ctime, :datetime, :null => false
|
14
|
+
t.column :mtime, :datetime, :null => false
|
15
|
+
t.column :start_datetime, :datetime, :null => false
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.down
|
20
|
+
drop_table :Flistzs
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class CreateInvalidflistz < ActiveRecord::Migration[6.0]
|
2
|
+
def self.up
|
3
|
+
create_table :invalidFlistzs do |t|
|
4
|
+
t.column :org_id, :int, :null => false
|
5
|
+
t.column :count_id, :int, :null => true
|
6
|
+
t.column :end_datetime, :datetime, :null => false
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.down
|
11
|
+
drop_table :invalidFlistzs
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class CreateCurrentflistz < ActiveRecord::Migration[6.0]
|
2
|
+
def self.up
|
3
|
+
execute <<-SQL
|
4
|
+
CREATE VIEW currentFlistzs AS SELECT id as org_id,
|
5
|
+
dir_id , level , kind , repo , path , project , desc , comment , atime , ctime , mtime , start_datetime
|
6
|
+
FROM Flistzs where not exists (select * from invalidFlistzs where invalidFlistzs.org_id = Flistzs.id )
|
7
|
+
SQL
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.down
|
11
|
+
execute <<-SQL
|
12
|
+
DROP VIEW currentFlistzs
|
13
|
+
SQL
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class CreateInvaliddirz < ActiveRecord::Migration[6.0]
|
2
|
+
def self.up
|
3
|
+
create_table :invalidDirzs do |t|
|
4
|
+
t.column :org_id, :int, :null => false
|
5
|
+
t.column :count_id, :int, :null => true
|
6
|
+
t.column :end_datetime, :datetime, :null => false
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.down
|
11
|
+
drop_table :invalidDirzs
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class CreateCurrentdirz < ActiveRecord::Migration[6.0]
|
2
|
+
def self.up
|
3
|
+
execute <<-SQL
|
4
|
+
CREATE VIEW currentDirzs AS SELECT id as org_id,
|
5
|
+
path , start_datetime
|
6
|
+
FROM Dirzs where not exists (select * from invalidDirzs where invalidDirzs.org_id = Dirzs.id )
|
7
|
+
SQL
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.down
|
11
|
+
execute <<-SQL
|
12
|
+
DROP VIEW currentDirzs
|
13
|
+
SQL
|
14
|
+
end
|
15
|
+
end
|
data/exe/flist
CHANGED
@@ -1,28 +1,81 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'flist'
|
5
|
+
require 'simpleoptparse'
|
6
|
+
|
7
|
+
banner = 'Usage: bundle exec ruby exe/flist --cmd=[s|fs1|fs2|fs3|fr] --config config-yaml --env env-yaml --verbose'
|
8
|
+
|
9
|
+
opts = {}
|
10
|
+
opts['verbose'] = false
|
11
|
+
begin
|
12
|
+
Simpleoptparse::Simpleoptparse.parse(ARGV, opts, banner, Flist::VERSION, nil) do |parser|
|
13
|
+
parser.on('--cmd=X', %w[s fs1 fs2 fs3 fr]) { |x| opts['cmd'] = x }
|
14
|
+
parser.on('--config=config-yaml') { |x| opts['config'] = x }
|
15
|
+
parser.on('--env=env-yaml') { |x| opts['env'] = x }
|
16
|
+
parser.on('--verbose') { |_x| opts['verbose'] = true }
|
17
|
+
end
|
18
|
+
rescue OptionParser::InvalidArgument => e
|
19
|
+
puts e.message
|
20
|
+
puts banner
|
21
|
+
exit Flist::EXIT_CODE_INVALID_CODE
|
22
|
+
end
|
23
|
+
cli = Flist::Cli.new(opts['verbose'])
|
24
|
+
hash = cli.setup
|
25
|
+
|
26
|
+
# puts "hash=#{hash}"
|
27
|
+
|
28
|
+
# opts['env'] = "env-a1.yaml"
|
29
|
+
# opts["config"] = "config/config.yml"
|
30
|
+
cmd = opts['cmd']
|
31
|
+
# p cmd
|
32
|
+
# p opts
|
33
|
+
case cmd
|
34
|
+
when 's'
|
35
|
+
cli.setup_config
|
36
|
+
when 'fs1'
|
37
|
+
fi = Flist::Flist.new(
|
38
|
+
hash,
|
39
|
+
opts
|
40
|
+
)
|
41
|
+
# fl.list_a
|
42
|
+
puts '= simple'
|
43
|
+
# listup_x('simple')
|
44
|
+
fi.listup_simple
|
45
|
+
|
46
|
+
fi.post_process
|
47
|
+
when 'fs2'
|
48
|
+
fi = Flist::Flist.new(
|
49
|
+
hash,
|
50
|
+
opts
|
51
|
+
)
|
52
|
+
|
53
|
+
puts '= simple2'
|
54
|
+
# listup_x('simple2')
|
55
|
+
fi.listup_simple2
|
56
|
+
|
57
|
+
fi.post_process
|
58
|
+
when 'fs3'
|
59
|
+
fi = Flist::Flist.new(
|
60
|
+
hash,
|
61
|
+
opts
|
62
|
+
)
|
63
|
+
puts '= simple3'
|
64
|
+
# listup_x('simple3')
|
65
|
+
fi.listup_simple3
|
66
|
+
|
67
|
+
fi.post_process
|
68
|
+
when 'fr'
|
69
|
+
fi = Flist::Flist.new(
|
70
|
+
hash,
|
71
|
+
opts
|
72
|
+
)
|
73
|
+
puts '= repo'
|
74
|
+
# listup_x('repo')
|
75
|
+
fi.listup_repo
|
76
|
+
|
77
|
+
fi.post_process
|
78
|
+
else
|
79
|
+
puts 'Invalid command 2'
|
80
|
+
puts banner
|
81
|
+
end
|
data/flist.gemspec
CHANGED
@@ -1,33 +1,46 @@
|
|
1
|
-
#
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
3
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
5
|
require 'flist/version'
|
5
6
|
|
6
7
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
8
|
+
spec.name = 'flist'
|
8
9
|
spec.version = Flist::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
10
|
+
spec.authors = ['yasuo kominami']
|
11
|
+
spec.email = ['ykominami@gmail.com']
|
12
|
+
|
13
|
+
spec.summary = 'get flie listing in local machine.'
|
14
|
+
spec.description = 'get flie listing in local machine.'
|
15
|
+
spec.homepage = ''
|
16
|
+
spec.license = 'MIT'
|
17
|
+
spec.required_ruby_version = '>= 2.7.0'
|
11
18
|
|
12
|
-
|
13
|
-
spec.
|
14
|
-
|
19
|
+
# if spec.respond_to?(:metadata)
|
20
|
+
# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com' to prevent pushes to rubygems.org, or delete to allow pushes to any server."
|
21
|
+
# else
|
22
|
+
# raise 'RubyGems 2.0 or newer is required to protect against public gem pushes.'
|
23
|
+
# end
|
15
24
|
|
16
25
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
-
spec.bindir =
|
26
|
+
spec.bindir = 'exe'
|
18
27
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
-
spec.require_paths = [
|
28
|
+
spec.require_paths = ['lib']
|
29
|
+
|
30
|
+
spec.add_runtime_dependency 'arxutils_sqlite3'
|
31
|
+
spec.add_runtime_dependency 'encx'
|
32
|
+
spec.add_runtime_dependency 'ykutils'
|
33
|
+
spec.add_runtime_dependency 'ykxutils'
|
20
34
|
|
21
|
-
|
22
|
-
# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com' to prevent pushes to rubygems.org, or delete to allow pushes to any server."
|
23
|
-
end
|
24
|
-
spec.add_dependency "rake", "~> 10.0"
|
35
|
+
spec.add_runtime_dependency 'evernote_oauth'
|
25
36
|
|
26
|
-
spec.add_runtime_dependency
|
27
|
-
spec.add_runtime_dependency
|
28
|
-
spec.add_runtime_dependency
|
29
|
-
spec.add_runtime_dependency
|
37
|
+
spec.add_runtime_dependency 'bundler'
|
38
|
+
spec.add_runtime_dependency 'rake'
|
39
|
+
spec.add_runtime_dependency 'rspec'
|
40
|
+
spec.add_runtime_dependency 'rubocop'
|
41
|
+
spec.add_runtime_dependency 'rubocop-rake'
|
42
|
+
spec.add_runtime_dependency 'rubocop-rspec'
|
30
43
|
|
31
|
-
spec.add_development_dependency
|
32
|
-
spec.
|
44
|
+
spec.add_development_dependency 'yard'
|
45
|
+
spec.metadata['rubygems_mfa_required'] = 'true'
|
33
46
|
end
|
data/lib/dbacrecord.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
module Flist
|
2
|
+
module Dbutil
|
3
|
+
class Count < ActiveRecord::Base
|
4
|
+
has_many :invalidFlistzs
|
5
|
+
has_many :invalidDirzs
|
6
|
+
end
|
7
|
+
|
8
|
+
class Countdatetime < ActiveRecord::Base
|
9
|
+
end
|
10
|
+
|
11
|
+
class Flistz < ActiveRecord::Base
|
12
|
+
end
|
13
|
+
|
14
|
+
class Invalidflistz < ActiveRecord::Base
|
15
|
+
belongs_to :flistz, foreign_key: 'org_id'
|
16
|
+
belongs_to :count, foreign_key: ''
|
17
|
+
end
|
18
|
+
|
19
|
+
class Currentflistz < ActiveRecord::Base
|
20
|
+
belongs_to :flistz, foreign_key: 'org_id'
|
21
|
+
end
|
22
|
+
|
23
|
+
class Dirz < ActiveRecord::Base
|
24
|
+
end
|
25
|
+
|
26
|
+
class Invaliddirz < ActiveRecord::Base
|
27
|
+
belongs_to :dirz, foreign_key: 'org_id'
|
28
|
+
belongs_to :count, foreign_key: ''
|
29
|
+
end
|
30
|
+
|
31
|
+
class Currentdirz < ActiveRecord::Base
|
32
|
+
belongs_to :dirz, foreign_key: 'org_id'
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
data/lib/flist/cli.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Flist
|
4
|
+
# コマンドライン処理クラス
|
5
|
+
class Cli
|
6
|
+
include Ykutils::DebugUtils
|
7
|
+
|
8
|
+
def initialize(verbose)
|
9
|
+
debug_utils_init
|
10
|
+
set_debug(verbose)
|
11
|
+
end
|
12
|
+
|
13
|
+
# 構成情報設定
|
14
|
+
def setup
|
15
|
+
setup_config
|
16
|
+
|
17
|
+
env = ENV.fetch('ENV', nil)
|
18
|
+
# env ||= "development"
|
19
|
+
env ||= 'production'
|
20
|
+
|
21
|
+
{
|
22
|
+
'db_dir' => Arxutils_Sqlite3::Config::DB_DIR,
|
23
|
+
'migrate_dir' => Arxutils_Sqlite3::Config::MIGRATE_DIR,
|
24
|
+
'config_dir' => Arxutils_Sqlite3::Config::CONFIG_DIR,
|
25
|
+
'dbconfig' => Arxutils_Sqlite3::Config::DBCONFIG_SQLITE3,
|
26
|
+
'env' => env,
|
27
|
+
'log_fname' => Arxutils_Sqlite3::Config::DATABASELOG,
|
28
|
+
'output_dir' => ::Flist::OUTPUT_DIR,
|
29
|
+
'pstore_dir' => ::Flist::PSTORE_DIR
|
30
|
+
}
|
31
|
+
end
|
32
|
+
|
33
|
+
def setup_config
|
34
|
+
scope = {}
|
35
|
+
value_hash = {}
|
36
|
+
content = Ykutils::Erubyx.erubi_render_with_template_file(::Flist::ERB_CONFIG_YAML_FILE, scope, value_hash)
|
37
|
+
File.write(::Flist::SAMPLE_CONFIG_YAML_FILE, content)
|
38
|
+
Ykxutils.yaml_load_compati(content)
|
39
|
+
end
|
40
|
+
|
41
|
+
# setting.ymlのロード
|
42
|
+
def load_config_yaml_file
|
43
|
+
# settingファイル
|
44
|
+
config_yaml_file = ::Flist::CONFIG_YAML_FILE
|
45
|
+
config = Ykxutils.yaml_load_compati(config_yaml_file) if config_yaml_file.exist?
|
46
|
+
config
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/lib/flist/config.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Flist
|
4
|
+
# 構成情報クラス
|
5
|
+
class Config
|
6
|
+
include Ykutils::DebugUtils
|
7
|
+
|
8
|
+
def setup_config
|
9
|
+
scope = {}
|
10
|
+
value_hash = {}
|
11
|
+
content = Ykutils::Erubyx.erubi_render_with_template_file(ERB_CONFIG_YAML_FILE, scope, value_hash)
|
12
|
+
Ykxutils.yaml_load_comati(content)
|
13
|
+
File.write(SAMPLE_CONFIG_YAML_FILE, content)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/flist/csvx.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Flist
|
4
|
+
# CSV操作用クラス
|
5
|
+
class Csvx
|
6
|
+
attr_reader :headers_s
|
7
|
+
attr_accessor :csv
|
8
|
+
|
9
|
+
# 初期化
|
10
|
+
def initialize(fname)
|
11
|
+
@headers_sym = %i[level kind repo path project comment atime ctime mtime]
|
12
|
+
@headers_s = @headers_sym.map(&:to_s)
|
13
|
+
|
14
|
+
@fname = fname
|
15
|
+
@csv = if @fname
|
16
|
+
CSV.open(@fname, 'w',
|
17
|
+
{ encoding: 'UTF-8',
|
18
|
+
headers: @headers_s,
|
19
|
+
force_quotes: true,
|
20
|
+
write_headers: true })
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# 終了処理
|
25
|
+
def finish
|
26
|
+
@csv&.close
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/flist/dbutil/dbmgr.rb
CHANGED
@@ -1,38 +1,39 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'active_record'
|
3
4
|
require 'forwardable'
|
4
5
|
require 'encx'
|
5
|
-
require 'flist/dbutil/flistzmgr'
|
6
|
-
require 'flist/dbutil/dirzmgr'
|
6
|
+
# require 'flist/dbutil/flistzmgr'
|
7
|
+
# require 'flist/dbutil/dirzmgr'
|
7
8
|
|
8
9
|
module Flist
|
9
10
|
module Dbutil
|
10
|
-
|
11
|
-
end
|
12
|
-
|
13
|
-
class Dirz < ActiveRecord::Base
|
14
|
-
end
|
15
|
-
|
16
|
-
class Invalidflistz < ActiveRecord::Base
|
17
|
-
end
|
18
|
-
|
19
|
-
class Currentflistz < ActiveRecord::Base
|
20
|
-
belongs_to :flistz , foreign_key: 'org_id'
|
21
|
-
end
|
22
|
-
|
11
|
+
# DBマネージャクラス
|
23
12
|
class DbMgr
|
24
13
|
extend Forwardable
|
25
|
-
|
26
|
-
def_delegators( :@flistzmgr , :post_process , :fl)
|
27
|
-
def_delegator( :@dirzmgr , :add , :dirz_add )
|
28
|
-
def_delegator( :@flistzmgr , :add , :flistz_add )
|
29
|
-
def_delegator( :@flistzmgr , :post_process , :flistz_post_process )
|
30
14
|
|
31
|
-
|
15
|
+
def_delegator(:@dirzmgr, :add, :dirz_add)
|
16
|
+
def_delegator(:@dirzmgr, :post_process, :dirz_post_process)
|
17
|
+
def_delegator(:@flistzmgr, :add, :flistz_add)
|
18
|
+
def_delegator(:@flistzmgr, :post_process, :flistz_post_process)
|
19
|
+
|
20
|
+
# 初期化
|
21
|
+
def initialize(register_time)
|
22
|
+
# DB接続タイムスタンプ
|
23
|
+
@register_time = register_time
|
24
|
+
# Flistを実行した回数とその時のDB接続タイムスタンプをDBに登録
|
25
|
+
@ct = Dbutil::Countdatetime.create(countdatetime: @register_time)
|
26
|
+
|
32
27
|
@db_encoding = Encoding::UTF_8
|
33
28
|
@encx = Encx::Encx.init(@db_encoding)
|
34
|
-
@flistzmgr = FlistzMgr.new(
|
35
|
-
@dirzmgr = DirzMgr.new(
|
29
|
+
@flistzmgr = FlistzMgr.new(@encx, @db_encoding, @register_time)
|
30
|
+
@dirzmgr = DirzMgr.new(@encx, @db_encoding, @register_time)
|
31
|
+
end
|
32
|
+
|
33
|
+
# 後処理
|
34
|
+
def post_process
|
35
|
+
dirz_post_process
|
36
|
+
flistz_post_process
|
36
37
|
end
|
37
38
|
end
|
38
39
|
end
|
data/lib/flist/dbutil/dirzmgr.rb
CHANGED
@@ -1,34 +1,97 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'pp'
|
3
4
|
require 'flist/dbutil/dbmgr'
|
4
5
|
|
5
6
|
module Flist
|
6
7
|
module Dbutil
|
8
|
+
# ディレクトリ情報マネージャ
|
7
9
|
class DirzMgr
|
8
|
-
|
10
|
+
include Ykutils::DebugUtils
|
11
|
+
|
12
|
+
# 初期化
|
13
|
+
def initialize(encx, db_encoding, register_time)
|
14
|
+
# 指定エンコーディングの基づいたパス操作
|
9
15
|
@encx = encx
|
16
|
+
# DBのエンコーディング
|
10
17
|
@db_encoding = db_encoding
|
18
|
+
# DB接続時のタイムスタンプ
|
11
19
|
@register_time = register_time
|
20
|
+
# DBに登録・更新したファイル情報をのハッシュ
|
21
|
+
# キーはパス
|
22
|
+
@hs_by_path = {}
|
23
|
+
# DBに登録・更新したファイル情報のハッシュ
|
24
|
+
# キーはファイル情報のobject_id
|
25
|
+
@hs_by_id = {}
|
26
|
+
# DBに登録・更新したディレクトリ情報に対応するパス
|
27
|
+
@set_of_dir_path = Set.new
|
12
28
|
end
|
13
29
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
30
|
+
# ディレクトリ情報追加・更新
|
31
|
+
# DBに未登録の時は追加し、登録済みの時は更新する
|
32
|
+
def add(path)
|
33
|
+
# pathをDBのエンコーディングに変換する
|
34
|
+
path_conv = @encx.convert(path, @db_encoding)
|
35
|
+
# パスが表すファイル情報をハッシュから得る
|
36
|
+
dirz = @hs_by_path[path]
|
37
|
+
# パスに対応するファイル情報が見つかれば何もしない
|
38
|
+
return dirz if dirz
|
39
|
+
|
40
|
+
# DirzのViewから、パスで指定したディレクトリ情報を得る
|
41
|
+
cur_dirz = Dbutil::Currentdirz.where(path: path_conv).limit(1)
|
42
|
+
if cur_dirz.size.zero?
|
43
|
+
# 見つからなければ、新たにファイル情報をDBに登録する
|
18
44
|
begin
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
45
|
+
d_puts '#### DirzMgr'
|
46
|
+
d_puts "path=#{path_conv}"
|
47
|
+
d_puts '#### FlistzMgr End'
|
48
|
+
dirz = Dirz.create(path: path_conv, start_datetime: @register_time)
|
49
|
+
rescue StandardError => e
|
50
|
+
p e.class
|
51
|
+
p e.message
|
52
|
+
pp e.backtrace
|
24
53
|
|
25
54
|
dirz = nil
|
26
55
|
end
|
27
56
|
else
|
28
|
-
|
57
|
+
# DBから見つかれば、最初に見つけたファイル情報を更新する
|
58
|
+
# current_curz = cur_dirz.first.dirz
|
59
|
+
current_dirz = cur_dirz[0].dirz
|
60
|
+
# hs = { atime: atime, ctime: ctime, mtime: mtime, repo: repo,
|
61
|
+
# project: project, desc: desc, comment: comment }
|
62
|
+
# value_hs = hs.each_with_object({}) do |item, hsx|
|
63
|
+
# hsx[item[0]] = item[1] if current_flistz[item[0]] != item[1]
|
64
|
+
# end
|
65
|
+
# current_flistz.update(value_hs) if value_hs.size.positive?
|
66
|
+
dirz = current_dirz
|
67
|
+
end
|
68
|
+
# DBに登録・更新したファイル情報をハッシュに格納
|
69
|
+
if dirz
|
70
|
+
@hs_by_path[path] = dirz
|
71
|
+
@hs_by_id[dirz.object_id] = dirz
|
72
|
+
@set_of_dir_path.add(path)
|
29
73
|
end
|
30
74
|
dirz
|
31
75
|
end
|
76
|
+
|
77
|
+
# 後処理
|
78
|
+
def post_process
|
79
|
+
@set_of_dir_path.each do |path|
|
80
|
+
post_process_for_dir_path(path)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
# 後処理(パス指定)
|
85
|
+
def post_process_for_dir_path(path)
|
86
|
+
h_ids = Currentdirz.where(path: path).pluck(:org_id)
|
87
|
+
t_ids = @hs_by_id.keys
|
88
|
+
ids = h_ids - t_ids
|
89
|
+
return unless ids.size.positive?
|
90
|
+
|
91
|
+
ids.each do |idx|
|
92
|
+
Invaliddirz.create(org_id: idx, end_datetime: @register_time)
|
93
|
+
end
|
94
|
+
end
|
32
95
|
end
|
33
96
|
end
|
34
97
|
end
|