Skip to content
This repository has been archived by the owner on Jun 23, 2022. It is now read-only.

Commit

Permalink
Revert "Improving handling of last access time"
Browse files Browse the repository at this point in the history
This reverts commit c638b7d.

Conflicts:
	src/com/google/enterprise/adaptor/fs/WindowsFileDelegate.java
  • Loading branch information
PapaJoltOmega committed Jul 23, 2014
1 parent b93564e commit e9c993c
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 111 deletions.
7 changes: 0 additions & 7 deletions src/com/google/enterprise/adaptor/fs/FileDelegate.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,6 @@ interface FileDelegate {
*/
BasicFileAttributes readBasicAttributes(Path doc) throws IOException;

/**
* Gets the lastAccess time for the file or directory.
*
* @param doc the file/folder to set the last accessed time on
*/
FileTime getLastAccessTime(Path doc) throws IOException;

/**
* Sets the lastAccess time for the file or directory.
*
Expand Down
21 changes: 8 additions & 13 deletions src/com/google/enterprise/adaptor/fs/FsAdaptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ public void getDocContent(Request req, Response resp) throws IOException {
}

final boolean docIsDirectory = attrs.isDirectory();
final FileTime lastAccessTime = delegate.getLastAccessTime(doc);
final FileTime lastAccessTime = attrs.lastAccessTime();

if (!docIsDirectory) {
if (lastAccessTimeFilter.excluded(lastAccessTime)) {
Expand Down Expand Up @@ -653,18 +653,13 @@ public void getDocContent(Request req, Response resp) throws IOException {
try {
input.close();
} finally {
// Do a follow up check to see if the last access time has changed.
// If the last access time has changed, attempt to reset it.
if (!lastAccessTime.equals(delegate.getLastAccessTime(doc))) {
log.log(Level.FINE, "Restoring last access time for {0}.", doc);
try {
delegate.setLastAccessTime(doc, lastAccessTime);
} catch (IOException e) {
// This failure can be expected. We can have full permissions
// to read but not write/update permissions.
log.log(Level.FINE,
"Unable to restore last access time for {0}.", doc);
}
try {
delegate.setLastAccessTime(doc, lastAccessTime);
} catch (IOException e) {
// This failure can be expected. We can have full permissions
// to read but not write/update permissions.
log.log(Level.CONFIG,
"Unable to restore last access time for {0}.", doc);
}
}
}
Expand Down
6 changes: 0 additions & 6 deletions src/com/google/enterprise/adaptor/fs/NioFileDelegate.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,6 @@ public BasicFileAttributes readBasicAttributes(Path doc) throws IOException {
return Files.readAttributes(doc, BasicFileAttributes.class);
}

@Override
public FileTime getLastAccessTime(Path doc) throws IOException {
return (FileTime)Files.getAttribute(doc, "lastAccessTime",
LinkOption.NOFOLLOW_LINKS);
}

@Override
public void setLastAccessTime(Path doc, FileTime time) throws IOException {
Files.setAttribute(doc, "lastAccessTime", time, LinkOption.NOFOLLOW_LINKS);
Expand Down
80 changes: 0 additions & 80 deletions src/com/google/enterprise/adaptor/fs/WindowsFileDelegate.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,14 @@
import com.sun.jna.ptr.PointerByReference;
import com.sun.jna.win32.W32APIOptions;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.attribute.AclEntry;
import java.nio.file.attribute.AclFileAttributeView;
import java.nio.file.attribute.FileTime;
import java.nio.file.Files;
import java.nio.file.LinkOption;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.CountDownLatch;
Expand Down Expand Up @@ -85,31 +81,6 @@ public WindowsFileDelegate() {
this.aclViews = aclViews;
}

@Override
public InputStream newInputStream(Path doc) throws IOException {
return new BufferedInputStream(new WinFileInputStream(doc));
}

@Override
public FileTime getLastAccessTime(Path doc) throws IOException {
WinBase.FILETIME.ByReference accessTime =
new WinBase.FILETIME.ByReference();
HANDLE handle = kernel32.CreateFile(doc.toString(), WinNT.GENERIC_READ,
WinNT.FILE_SHARE_READ | WinNT.FILE_SHARE_WRITE,
new WinBase.SECURITY_ATTRIBUTES(), WinNT.OPEN_EXISTING,
WinNT.FILE_ATTRIBUTE_NORMAL, null);
if (Kernel32.INVALID_HANDLE_VALUE.equals(handle)) {
throw new IOException("Unable to open " + doc
+ ". GetLastError: " + kernel32.GetLastError());
}
try {
kernel32.GetFileTime(handle, null, accessTime, null);
} finally {
kernel32.CloseHandle(handle);
}
return FileTime.fromMillis(accessTime.toDate().getTime());
}

@Override
public AclFileAttributeViews getAclViews(Path doc) throws IOException {
return aclViews.getAclViews(doc);
Expand Down Expand Up @@ -518,55 +489,4 @@ int WaitForSingleObjectEx(HANDLE hHandle, int dwMilliseconds,
public void destroy() {
stopMonitorPath();
}

private class WinFileInputStream extends InputStream {
private final HANDLE handle;

public WinFileInputStream(Path path) throws IOException {
handle = kernel32.CreateFile(path.toString(),
WinNT.GENERIC_READ | WinNT.GENERIC_WRITE,
WinNT.FILE_SHARE_READ | WinNT.FILE_SHARE_WRITE,
new WinBase.SECURITY_ATTRIBUTES(),
WinNT.OPEN_EXISTING, WinNT.FILE_ATTRIBUTE_NORMAL, null);
if (Kernel32.INVALID_HANDLE_VALUE.equals(handle)) {
throw new IOException("Unable to open " + path
+ ". GetLastError: " + kernel32.GetLastError());
}

// Call SetFileTime with a value of 0xFFFFFFFF for lpLastAccessTime
// to keep Windows from updating the last access time
// when reading the file content.
WinBase.FILETIME ft = new WinBase.FILETIME();
ft.dwHighDateTime = 0xFFFFFFFF;
ft.dwLowDateTime = 0xFFFFFFFF;
kernel32.SetFileTime(handle, null, ft, null);
}

@Override
public int read() throws IOException {
throw new UnsupportedOperationException();
}

@Override
public int read(byte[] inBuf, int start, int count) throws IOException {
IntByReference lpNumberOfBytesRead = new IntByReference(0);
boolean result = kernel32.ReadFile(handle,
ByteBuffer.wrap(inBuf, start, count), count,
lpNumberOfBytesRead, null);
if (!result) {
throw new IOException("Unable to read file data. "
+ "GetLastError: " + kernel32.GetLastError());
}
if (lpNumberOfBytesRead.getValue() != 0) {
return lpNumberOfBytesRead.getValue();
} else {
return -1;
}
}

@Override
public void close() throws IOException {
kernel32.CloseHandle(handle);
}
}
}
5 changes: 0 additions & 5 deletions test/com/google/enterprise/adaptor/fs/MockFileDelegate.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,6 @@ public BasicFileAttributes readBasicAttributes(Path doc) throws IOException {
return getFile(doc).readBasicAttributes();
}

@Override
public FileTime getLastAccessTime(Path doc) throws IOException {
return readBasicAttributes(doc).lastAccessTime();
}

@Override
public void setLastAccessTime(Path doc, FileTime time) throws IOException {
getFile(doc).setLastAccessTime(time);
Expand Down

0 comments on commit e9c993c

Please sign in to comment.