untouch  untouch

go to home page Student Projects full screen, hide local find menu Google search web for more information on this topic jump to foot of page translate this page with Babelfish ©1996-2009 Roedy Green, Canadian Mind Products
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 an 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 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 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. 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:


CMP homejump to top You can get the freshest copy of this page from: or possibly from your local J: drive (Java virtual drive/mindprod.com website mirror)
http://mindprod.com/project/untouchproj.html J:\mindprod\project\untouchproj.html
CMP logofeedback Please email your feedback for publication, errors, omissions, typos, formatting errors, ambiguities, unclear wording, broken/redirected link reports, suggestions to improve this page or comments to Roedy Green : feedback email
mindprod.com IP:[65.110.21.43]
view BlogYour face IP:[38.107.191.109]
You are visitor number 2,414.