| 63889 |
murdoch |
1 |
% File src/library/utils/man/changedFiles.Rd
|
| 68948 |
ripley |
2 |
% Part of the R package, https://www.R-project.org
|
| 63889 |
murdoch |
3 |
% Copyright 2013 R Core Team
|
|
|
4 |
% Distributed under GPL 2 or later
|
|
|
5 |
|
|
|
6 |
\name{changedFiles}
|
|
|
7 |
\alias{fileSnapshot}
|
|
|
8 |
\alias{changedFiles}
|
|
|
9 |
\alias{print.changedFiles}
|
|
|
10 |
\alias{print.fileSnapshot}
|
| 73574 |
hornik |
11 |
\title{Detect which Files Have Changed}
|
| 63889 |
murdoch |
12 |
\description{
|
|
|
13 |
\code{fileSnapshot} takes a snapshot of a selection of files,
|
|
|
14 |
recording summary information about each. \code{changedFiles}
|
|
|
15 |
compares two snapshots, or compares one snapshot to the current state
|
|
|
16 |
of the file system. The snapshots need not be the same directory;
|
|
|
17 |
this could be used to compare two directories.
|
|
|
18 |
}
|
|
|
19 |
\usage{
|
|
|
20 |
fileSnapshot(path = ".", file.info = TRUE, timestamp = NULL,
|
|
|
21 |
md5sum = FALSE, digest = NULL, full.names = length(path) > 1,
|
|
|
22 |
...)
|
|
|
23 |
|
|
|
24 |
changedFiles(before, after, path = before$path, timestamp = before$timestamp,
|
|
|
25 |
check.file.info = c("size", "isdir", "mode", "mtime"),
|
|
|
26 |
md5sum = before$md5sum, digest = before$digest,
|
|
|
27 |
full.names = before$full.names, ...)
|
|
|
28 |
|
|
|
29 |
\S3method{print}{fileSnapshot}(x, verbose = FALSE, ...)
|
|
|
30 |
|
|
|
31 |
\S3method{print}{changedFiles}(x, verbose = FALSE, ...)
|
|
|
32 |
}
|
|
|
33 |
|
|
|
34 |
\arguments{
|
|
|
35 |
|
|
|
36 |
\item{path}{character vector; the path(s) to record. }
|
|
|
37 |
\item{file.info}{logical; whether to record \code{\link{file.info}}
|
|
|
38 |
values for each file.
|
|
|
39 |
}
|
|
|
40 |
|
|
|
41 |
\item{timestamp}{character string or \code{NULL}; the name of a file
|
|
|
42 |
to write at the time the snapshot is taken. This gives a quick test
|
|
|
43 |
for modification, but may be unreliable; see the Details. }
|
|
|
44 |
|
|
|
45 |
\item{md5sum}{logical; whether MD5 summaries of each file should be
|
|
|
46 |
taken as part of the snapshot. }
|
|
|
47 |
|
|
|
48 |
\item{digest}{a function or \code{NULL}; a function with header
|
|
|
49 |
\code{function(filename)} which will take a vector of filenames and
|
|
|
50 |
produce a vector of values of the same length, or a matrix with that
|
|
|
51 |
number of rows. }
|
|
|
52 |
|
|
|
53 |
\item{full.names}{logical; whether full names (as in
|
|
|
54 |
\code{\link{list.files}}) should be recorded. Must be \code{TRUE} if
|
|
|
55 |
\code{length(path) > 1}. }
|
|
|
56 |
|
|
|
57 |
\item{\dots}{ additional parameters to pass to
|
|
|
58 |
\code{\link{list.files}} to control the set of files in the snapshots.
|
|
|
59 |
}
|
|
|
60 |
|
|
|
61 |
\item{before, after}{objects produced by \code{fileSnapshot}; two
|
|
|
62 |
snapshots to compare. If \code{after} is missing, a new snapshot of
|
|
|
63 |
the current file system will be produced for comparison, using
|
|
|
64 |
arguments recorded in \code{before} as defaults. }
|
|
|
65 |
|
|
|
66 |
\item{check.file.info}{character vector; which columns from
|
|
|
67 |
\code{\link{file.info}} should be compared. }
|
|
|
68 |
|
|
|
69 |
\item{x}{the object to print. }
|
|
|
70 |
|
|
|
71 |
\item{verbose}{logical; whether to list all data when printing. }
|
|
|
72 |
|
|
|
73 |
}
|
|
|
74 |
\details{
|
|
|
75 |
|
|
|
76 |
The \code{fileSnapshot} function uses \code{\link{list.files}} to
|
|
|
77 |
obtain a list of files, and depending on the \code{file.info},
|
|
|
78 |
\code{md5sum}, and \code{digest} arguments, records information about
|
|
|
79 |
each file.
|
|
|
80 |
|
|
|
81 |
The \code{changedFiles} function compares two snapshots.
|
|
|
82 |
|
|
|
83 |
If the \code{timestamp} argument to \code{fileSnapshot} is length 1, a
|
|
|
84 |
file with that name is created. If it is length 1 in
|
|
|
85 |
\code{changedFiles}, the \code{\link{file_test}} function is used to
|
|
|
86 |
compare the age of all files common to both \code{before} and
|
|
|
87 |
\code{after} to it. This test may be unreliable: it compares the
|
|
|
88 |
current modification time of the \code{after} files to the timestamp;
|
|
|
89 |
that may not be the same as the modification time when the
|
|
|
90 |
\code{after} snapshot was taken. It may also give incorrect results
|
|
|
91 |
if the clock on the file system holding the timestamp differs from the
|
|
|
92 |
one holding the snapshot files.
|
|
|
93 |
|
|
|
94 |
If the \code{check.file.info} argument contains a non-empty character
|
|
|
95 |
vector, the indicated columns from the result of a call to
|
|
|
96 |
\code{\link{file.info}} will be compared.
|
|
|
97 |
|
|
|
98 |
If \code{md5sum} is \code{TRUE}, \code{fileSnapshot} will call the
|
|
|
99 |
\code{tools::\link{md5sum}} function to record the 32 byte MD5
|
|
|
100 |
checksum for each file, and \code{changedFiles} will compare the
|
|
|
101 |
values. The \code{digest} argument allows users to provide their own
|
|
|
102 |
digest function.
|
|
|
103 |
|
|
|
104 |
}
|
|
|
105 |
|
|
|
106 |
\value{
|
|
|
107 |
|
|
|
108 |
\code{fileSnapshot} returns an object of class \code{"fileSnapshot"}.
|
|
|
109 |
This is a list containing the fields
|
|
|
110 |
|
| 63966 |
ripley |
111 |
\item{info}{a data frame whose rownames are the filenames, and whose
|
| 63889 |
murdoch |
112 |
columns contain the requested snapshot data}
|
|
|
113 |
|
|
|
114 |
\item{path}{the normalized \code{path} from the call}
|
|
|
115 |
|
|
|
116 |
\item{timestamp, file.info, md5sum, digest, full.names}{a record of
|
|
|
117 |
the other arguments from the call}
|
|
|
118 |
|
|
|
119 |
\item{args}{other arguments passed via \code{...} to
|
|
|
120 |
\code{\link{list.files}}.}
|
|
|
121 |
|
|
|
122 |
\code{changedFiles} produces an object of class \code{"changedFiles"}.
|
|
|
123 |
This is a list containing
|
|
|
124 |
|
|
|
125 |
\item{added, deleted, changed, unchanged}{character vectors of
|
|
|
126 |
filenames from the before and after snapshots, with obvious meanings}
|
|
|
127 |
|
|
|
128 |
\item{changes}{a logical matrix with a row for each common file, and a
|
|
|
129 |
column for each comparison test. \code{TRUE} indicates a change in
|
|
|
130 |
that test.}
|
|
|
131 |
|
|
|
132 |
\code{\link{print}} methods are defined for each of these types. The
|
|
|
133 |
\code{\link{print}} method for \code{"fileSnapshot"} objects
|
|
|
134 |
displays the arguments used to produce them, while the one for
|
|
|
135 |
\code{"changedFiles"} displays the \code{added}, \code{deleted} and
|
|
|
136 |
\code{changed} fields if non-empty, and a submatrix of the
|
|
|
137 |
\code{changes} matrix containing all of the \code{TRUE} values.
|
|
|
138 |
|
|
|
139 |
}
|
|
|
140 |
|
|
|
141 |
\author{
|
|
|
142 |
Duncan Murdoch, using suggestions from Karl Millar and others.
|
|
|
143 |
}
|
|
|
144 |
|
|
|
145 |
\seealso{
|
|
|
146 |
\code{\link{file.info}}, \code{\link{file_test}}, \code{\link{md5sum}}.
|
|
|
147 |
}
|
|
|
148 |
|
|
|
149 |
\examples{
|
|
|
150 |
# Create some files in a temporary directory
|
|
|
151 |
dir <- tempfile()
|
|
|
152 |
dir.create(dir)
|
|
|
153 |
writeBin(1L, file.path(dir, "file1"))
|
|
|
154 |
writeBin(2L, file.path(dir, "file2"))
|
|
|
155 |
dir.create(file.path(dir, "dir"))
|
|
|
156 |
|
|
|
157 |
# Take a snapshot
|
|
|
158 |
snapshot <- fileSnapshot(dir, timestamp = tempfile("timestamp"), md5sum=TRUE)
|
| 81559 |
smeyer |
159 |
\dontshow{Sys.sleep(.01)} % avoid spurious Rdiff below
|
| 63889 |
murdoch |
160 |
# Change one of the files.
|
|
|
161 |
writeBin(3L:4L, file.path(dir, "file2"))
|
|
|
162 |
|
|
|
163 |
# Display the detected changes. We may or may not see mtime change...
|
|
|
164 |
changedFiles(snapshot)
|
|
|
165 |
changedFiles(snapshot)$changes
|
|
|
166 |
}
|
|
|
167 |
\keyword{utilities}
|
|
|
168 |
\keyword{file}
|