immosquare-cleaner 0.1.98 → 0.1.100

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 60bff9974fe4c15e971b28c1d421390683f6e92a49c811874d81eb0d702881ae
4
- data.tar.gz: bd98dd8e709d0c02f092eca91d70ca92404a3e99e854d02119fcc537eddf1688
3
+ metadata.gz: 324a42a5ed05dbe121f64e70830e45256dfb487c9d46770b8d7966b0305029cb
4
+ data.tar.gz: 13068735b1de6eb9e780bcac325df9eb7d8aa63ddeec43371c611ca516fbfa6c
5
5
  SHA512:
6
- metadata.gz: 80d02e9965ce804c5ff8f1c4fe9b95683ec04658d02dade1f5275a156965c5405f7d49696d148996e460f08dff824fbf1dfe22d701bd140819e140a3ba07f7cc
7
- data.tar.gz: e74fbd3e6d894f8407bd31bbcc8270d65f1f341f8f02a20a87e7d6724c480a0115bc13a69362027a0bf46841b099c79c7e9230651a06a6e1dbfa2dfb5f5410ec
6
+ metadata.gz: b950416777f5646c0040bbf9fc57976f48203aea11a4dac485d00d874ac605df2df41de0651b9f1522871fa6642ed1f5d97560941821b7508b48899513d10d7f
7
+ data.tar.gz: e80fc90a41c7d5322bd1ece1fb2d2694e669821d056792ab8ea287a66c6863b690eda6cb0896abe86b4c81918bb6dec57136a0f87a2c9b5ddcc637322ee86305
@@ -2,6 +2,7 @@
2
2
 
3
3
  require "immosquare-cleaner"
4
4
  require "optparse"
5
+ require "digest"
5
6
 
6
7
  ##============================================================##
7
8
  ## Prevent "invalid byte sequence in US-ASCII" error on some files (eg: yaml)
@@ -27,7 +28,9 @@ options = {}
27
28
  ##============================================================##
28
29
  OptionParser.new do |parser|
29
30
  parser.banner = "Usage: immosquare-cleaner [options] file"
30
-
31
+ parser.on("-p", "--prevent-concurrent-write", "Prevent concurrent write") do
32
+ options[:prevent_concurrent_write] = true
33
+ end
31
34
  parser.on("-h", "--help", "Prints this help") do
32
35
  puts(parser)
33
36
  exit
@@ -70,4 +73,28 @@ end
70
73
  ## We can now call the clean method, passing the file absolute path and options
71
74
  ##============================================================##
72
75
  file_path = File.expand_path(file_path)
73
- ImmosquareCleaner.clean(file_path, **options)
76
+ if options[:prevent_concurrent_write]
77
+ ##============================================================##
78
+ ## concurrent write detection
79
+ ## wait 2s for the ide to do a pre-processing, then 3 cases :
80
+ ## - if the original file changed during the clean, give up
81
+ ## - if the cleaned file has the same checksum, do nothing
82
+ ## - else, erase the original file with the cleaned one
83
+ ##============================================================##
84
+ sleep(2)
85
+ before = Digest::MD5.file(file_path)
86
+ temp_path = "/tmp/#{file_path}"
87
+ FileUtils.mkdir_p(File.dirname(temp_path))
88
+ FileUtils.copy(file_path, temp_path)
89
+ ImmosquareCleaner.clean(temp_path, **options)
90
+ if Digest::MD5.file(file_path) != before
91
+ puts("Original file has changed, giving up cleaning.")
92
+ elsif Digest::MD5.file(temp_path) == before
93
+ puts("Cleaner had nothing to do, moving on.")
94
+ else
95
+ puts("Overwriting original file with cleaned version.")
96
+ FileUtils.move(temp_path, file_path)
97
+ end
98
+ else
99
+ ImmosquareCleaner.clean(file_path, **options)
100
+ end
@@ -1,3 +1,3 @@
1
1
  module ImmosquareCleaner
2
- VERSION = "0.1.98".freeze
2
+ VERSION = "0.1.100".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: immosquare-cleaner
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.98
4
+ version: 0.1.100
5
5
  platform: ruby
6
6
  authors:
7
7
  - immosquare