image provider

untouch


This essay is about a suggested student project in Java programming. This essay gives a rough overview of how it might work. It does not describe an actual complete program. I have no source, object, specifications, file layouts or anything else useful to implementing this project. Everything I have to say to help you with this project is written below. I am not prepared to help you implement it; I have too many other projects of my own.

You have my full permission to implement this project any way you please.

This student project is unusual in that I have already implemented it myself. You can download the . source code.

I often run bulk processes on files such as:

A side effect of this is the file is redated, even if the process has no effect on the file. I want to be able to redate unchanged files back to their old dates and times if they are actually unchanged.

This will save, for example, spuriouly uploading unchanged files to my website. It will also give me accurate dates a when file content was actually changed.

Implementation

There is a file in each directory called people/seal/untouch.digest It is a snapshot of the list of files in that directory, the date/time stamp last modified, the file length and a digest (a checksum). 64-bits ought to do it, but a 32-bit Adlerian would be faster. It is not the end of the world if a file is misdated because of a low probabilty clash of matching checksums.

Every time you run the utility, it recomputes the digests for each file. If they match, it sets the file back to the old date. If they don’t it notes the new timestamp and digest in the people/seal/untouch.digest file.

Tests for file equality compare the file length, then if that matches compare the digest. You don’t need to recompute digests for files whose lengths have not changed or dates have not changed.

It deals with new files and deleted files in the obvious way.

As an add on feature, redate the files back, whether they match or not. This lets you preserve the old dates when there have only been cosmetic changes.

The trickiest part of this project is writing the tiny piece of JNI (Java Native Interface) code to set the date on a file. Unfortunately, this is not supported in pure Java.

You need first to get a handle to the file with the Window’s API (Application Programming Interface) CreateFile. This function is misnamed. It does not create a file; it creates a file handle; it opens the file.

HANDLE CreateFile(
LPCTSTR lpFileName, // address of name of the file
GENERIC_WRITE, // access (read-write) mode // changing dates is considered writing.
FILE_SHARE_READ|FILE_SHARE_WRITE, // share mode
NULL, // address of security descriptor
OPEN_EXISTING, // how to create
0, // file attributes
NULL // handle of file with attributes to copy
);

The SetFileTime function sets the date and time that a file was created, last accessed, or last modified. Java timestamps use 64-bit milliseconds since 1970 GMT (Greenwich Mean Time). Windows timestamps use 64-bit value representing the number of 100-nanosecond intervals since January 1, 1601. Microsoft uses the Gregorian calendar ignoring the missing 12 days between 1752 Sep 2 Wednesday and by 1752 Sep 14 Thursday.

windowsTime = ( javaTime + 11644473600000L ) * 10000;
BOOL SetFileTime(
HANDLE hFile, // identifies the file
CONST FILETIME * lpftCreation, // time the file was created. little endian.
// NULL to leave as is.
CONST FILETIME * lpftLastAccess, // time the file was last accessed.
// NULL to leave as is.
CONST FILETIME * lpftLastWrite // time the file was last written.
);

As you might guess from my detailed instructions, I have written an untouch utility already. Mine uses pure java and supports several command line switches:


This page is posted
on the web at:

http://mindprod.com/project/untouchproj.html

Optional Replicator mirror
of mindprod.com
on local hard disk J:

J:\mindprod\project\untouchproj.html
logo
Please the feedback from other visitors, or your own feedback about the site.
Contact Roedy. Please feel free to link to this page without explicit permission.

IP:[65.110.21.43]
Your face IP:[54.205.54.215]
You are visitor number