win32_filetime 0.0.3 → 0.0.4

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
  SHA1:
3
- metadata.gz: 830f1f3edc8a98b28d8e31f67292287de8cf6889
4
- data.tar.gz: b0b5e8a8c21fcfac1cbe2f96d38a7592bbd49da8
3
+ metadata.gz: bfec75656526105c2346b005cb0879b11803f724
4
+ data.tar.gz: 803e386dd888deb474fdae573c2b91d044437c1b
5
5
  SHA512:
6
- metadata.gz: 3a7adf57edf0860b6995e8677f67c72a4d4d3df7bc53baef2b929c8967292935b89c463ec9d4d2b9546f37c8b9233992b43b6b52c3237ab74c6c7a51f11d7d47
7
- data.tar.gz: 13cfd910e9d73a6456387a4de6973117ac8086d7d84f8fdd5f723ccca8c4dc80730aba287611058bade1481e3f48973d7be8970d152e3aa6de4a7cb65e76b77f
6
+ metadata.gz: 09e8735b0ee1577da9be12df50105e39efb6aab65f80726168152a23ab62e482b57ff635341e16d0df520f5e3f30160048d559d89a6fe8570272f34bd9fda26f
7
+ data.tar.gz: fd963772426cb6019dedb7b21ce2d5a9c1506507403b90cc43dcae77ac8665c8601f420445279a4dfbe5e3c6dd324f5dc5e539d76afbf2efdfd209be709ed02f
data/bin/restoreoldtimes CHANGED
@@ -15,9 +15,10 @@ def rolloldtime(d1, fn)
15
15
  Dir.chdir(d1) do
16
16
  File.foreach(fn) do |line|
17
17
  line.strip!
18
- next if line.empty? || line[0] == '#'
18
+ next if line.empty?
19
+ p1 = line.index(/ 0x\w+ 0x\w+ 0x\w+ \d+$/)
20
+ next if !p1
19
21
 
20
- p1 = line.index(/ 0x\w+ 0x\w+ 0x\w+ \d+/)
21
22
  fn = line[0...p1]
22
23
  next if !File.file?(fn) && !File.directory?(fn)
23
24
 
@@ -1,3 +1,3 @@
1
1
  module Win32Filetime
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
data/lib/win32ft.rb CHANGED
@@ -122,7 +122,7 @@ class HANDLE < FFI::Struct
122
122
  layout :handle, :uint
123
123
  end
124
124
 
125
- class CFflag
125
+ module CFflag
126
126
  GENERIC_READ = 0x80000000
127
127
  GENERIC_WRITE = 0x40000000
128
128
  GENERIC_EXECUTE = 0x20000000
@@ -151,6 +151,24 @@ class CFflag
151
151
  FILE_FLAG_FIRST_PIPE_INSTANCE =0x00080000
152
152
  end
153
153
 
154
+ module FA
155
+ FILE_ATTRIBUTE_READONLY =0x00000001
156
+ FILE_ATTRIBUTE_HIDDEN =0x00000002
157
+ FILE_ATTRIBUTE_SYSTEM =0x00000004
158
+ FILE_ATTRIBUTE_DIRECTORY =0x00000010
159
+ FILE_ATTRIBUTE_ARCHIVE =0x00000020
160
+ FILE_ATTRIBUTE_DEVICE =0x00000040
161
+ FILE_ATTRIBUTE_NORMAL =0x00000080
162
+ FILE_ATTRIBUTE_TEMPORARY =0x00000100
163
+ FILE_ATTRIBUTE_SPARSE_FILE =0x00000200
164
+ FILE_ATTRIBUTE_REPARSE_POINT =0x00000400
165
+ FILE_ATTRIBUTE_COMPRESSED =0x00000800
166
+ FILE_ATTRIBUTE_OFFLINE =0x00001000
167
+ FILE_ATTRIBUTE_NOT_CONTENT_INDEXED =0x00002000
168
+ FILE_ATTRIBUTE_ENCRYPTED =0x00004000
169
+ FILE_ATTRIBUTE_VIRTUAL =0x00010000
170
+ end
171
+
154
172
  module Win32ft
155
173
  extend FFI::Library
156
174
  ffi_lib 'msvcrt', 'kernel32'
@@ -210,6 +228,8 @@ module Win32ft
210
228
  GetLocalTime(lt)
211
229
  lt
212
230
  end
231
+ attach_function :GetFileAttributes, :GetFileAttributesA, [:string], :ulong
232
+ attach_function :SetFileAttributes, :SetFileAttributesA, [:string, :ulong], :bool
213
233
 
214
234
  =begin
215
235
  CreateFileA("", GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0)
@@ -272,6 +292,8 @@ CloseHandle(HANDLE)
272
292
  ttts
273
293
  end
274
294
  def self.setfiletime(fn, tc, ta, tm)
295
+ fattr = GetFileAttributes(fn)
296
+ SetFileAttributes(fn, fattr & ~FA::FILE_ATTRIBUTE_READONLY) if fattr & FA::FILE_ATTRIBUTE_READONLY
275
297
  hf = CreateFileA(fn, CFflag::GENERIC_WRITE, CFflag::FILE_SHARE_READ | CFflag::FILE_SHARE_WRITE,
276
298
  nil, CFflag::OPEN_EXISTING, CFflag::FILE_FLAG_BACKUP_SEMANTICS, 0)
277
299
  raise "setfiletime: Can not open file \"#{fn}\"" if hf == -1
@@ -281,6 +303,7 @@ CloseHandle(HANDLE)
281
303
  res = SetFileTime(hf, tc, ta, tm)
282
304
  raise "setfiletime: SetFileTime error." if !res
283
305
  CloseHandle(hf)
306
+ SetFileAttributes(fn, fattr) if fattr & FA::FILE_ATTRIBUTE_READONLY
284
307
  true
285
308
  end
286
309
  def self.copyfiletime(fn1, fn2)
@@ -300,4 +300,13 @@ describe "GetFileTime SetFileTime" do
300
300
  Dir.rmdir 'a' rescue nil
301
301
  Dir.rmdir 'b' rescue nil
302
302
  end
303
+ it "SetFileAttributes" do
304
+ fn = "1.txt"
305
+ File.write(fn, "asdfadsf")
306
+ tc, ta, tm = Win32ft.getfiletime(fn)
307
+ FileTime.should === tc
308
+ FileUtils.chmod(0000, fn)
309
+ Win32ft.setfiletime(fn, tc, ta, tm).should == true
310
+ FileUtils.rm(fn)
311
+ end
303
312
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: win32_filetime
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - windwiny