I am using unison to sync a bunch of folders together. Not just 2 roots, but I think my question can be made this simple...
Lets say I am syncing directory A and B using unison. If I remove file X from directory A, how does unison know what to do? Should it add X back to A from B or should it delete X from B?
Unison keeps a record of the contents of each path after each successful synchronization of that path (i.e., it remembers the contents at the last moment when they were the same in the two replicas).
We say that a path is updated (in some replica) if its current contents are different from its contents the last time it was successfully synchronized. Note that whether a path is updated has nothing to do with its last modification time—Unison considers only the contents when determining whether an update has occurred. This means that touching a file without changing its contents will not be recognized as an update. A file can even be changed several times and then changed back to its original contents; as long as Unison is only run at the end of this process, no update will be recognized.
In other words: Unison knows that you have deleted file X, because it's no longer on the disk in A, it knows it should delete it from B.
Related
I'm writing a program/utility in C to find (and then move to a new directory) the files in the current directory that have been modified after the last time the utility was run.
What I'm trying to find out is if there is a way to find the last time this utility ran. Or alternatively, a way to store the time in the program (so as to compare the last stored time against the current time, and then update the "last time" variable to current time).
As I type this it occurs to me that I could write the time to a file (overwriting the single entry as the utility is run) and retrieve the value from the file in the program, although I don't know if this would be the best approach.
you can make a class contains info and serialize it to a text file , it's more easy to access and can store multiple values,
then to store new values first delete file and then create file again.
another approach could be a register key containing information.
hope it would be useful ;)
You can use the last access time from the filesystem (In GNU/linux you can use ls -lu to see last access time).
This is not a portable solution because it depends on filesystem and filesystem settings (see JoachimPileborg edit below)
Moreover look at this question to get last acces time in C (use atime instead of mtime).
I want to create a log file in Scheme, but every time I add a new entry, I want it to be at the beginning of the file, so when I read X number of logs from the file again, it reads the X newest entries from new to old.
Example:
22/02/14 13:50 Newest log entry
22/02/14 13:45 Older log entry
22/02/14 13:40 Oldest log entry
Does anyone know how to do this using the 'open-input-file' and 'open-output-file' procedures?
The functionality you are requesting you need to write the whole logfile every time you need to write a new entry because you will overwrite the previous first entry with the next. Usually programs don't keep the commited parts of a logfile so this introduces more memory usage and your program must know when the log is being rotated to clear the buffer.
The standard way is to append a new entry, which leaves the previous log entries where the last log write put them.
As a compromise you might look for a program that displays a log file in the reverse order and prehaps tails it like that too. It's easy to implement so I guess it would exist already. Writing such an app if it doesn't exist would be trivial.
I'm running a loop that takes names from a file.
What I want to do is when the name is taken, it then deletes it from the file. How can I do this?
Try out fileinput.
It goes something like:
import fileinput
for line in fileinput.input(someFileName, inplace=True):
doSomething()
Any line iterated over is consumed, hence deleted from the file.
If you need to keep it just print it, it'll be rewritten to the file in the same location.
i.e. if you won't print the line back it'll disappear :)
Native files don't work that way. You'd have to rewrite the entire list of remaining files, each time through the loop. Performance will be bad (unless the list of files is always very short). And the failure modes are very bad if your process crashes while you're trying to update the file because you can't do the update in place. The best you could do is: write to a temp file, delete the original file, then rename (or move) the temp file.
Instead, you should consider using SQLite. You could either delete records from a File table, or have a status field that tracks which files have been processed.
consider the following task :
1) read a target directory contents, pass each found dirent structure to some filter function and remember filtered elements somehow for the later processing
2) some time later, iterate through the filtered elements and process them (do some I/O)
The most obvious way is to save names of sub-directories.
However, I want to keep memory usage to the minimum and to avoid additional I/O.
According to POSIX manuals, I can save position of each directory entry using telldir() and restore them later using seekdir(). To keep these positions valid, I have to keep target directory opened and to not use rewinddir() call.
Keeping a directory stream open and storing a list of dir positions(long int`s) seems to be an appropriate solution.
However, it is unclear whether stored positions remain valid after folder modification. I didn`t found any comments on these conditions in the POSIX standard.
1) Whether stored positions remain valid when only new directory entries are added/removed ?
2) Whether stored positions of unmodified directory entries remain valid in case of some of the filtered directory entries were removed ?
3) Is it possible for the stored position to point to another directory entry after folder modification ?
It is easy to test and find out the answer on these questions for the particular system, but I would like to know what standards say on this topic
Thank you
Until you call rewinddir or close and reopen the directory, your view of the directory contents should not change. Sorry I don't have the reference handy. I'll find it later if you need it.
I've got a service which runs all the time and also keeps a log file. It basically adds new lines to the log file every few seconds. I'm written a small file which reads these lines and then parses them to various actions. The question I have is how can I delete the lines which I have already parsed from the log file without disrupting the writing of the log file by the service?
Usually when I need to delete a line in a file then I open the original one and a temporary one and then I just write all the lines to the temp file except the original which I want to delete. Obviously this method will not word here.
So how do I go about deleting them ?
In most commonly used file systems you can't delete a line from the beginning of a file without rewriting the entire file. I'd suggest instead of one large file, use lots of small files and rotate them for example once per day. The old files are deleted when you no longer need them.
Can't be done, unfortunately, without rewriting the file, either in-place or as a separate file.
One thing you may want to look at is to maintain a pointer in another file, specifying the position of the first unprocessed line.
Then your process simply opens the file and seeks to that location, processes some lines, then updates the pointer.
You'll still need to roll over the files at some point lest they continue to grow forever.
I'm not sure, but I'm thinking in this way:
New Line is a char, so you must delete chars for that line + New Line char
By the way, "moving" all characters back (to overwrite the old line), is like copying each character in a different position, and removing them from their old position
So no, I don't think you can just delete a line, you should rewrite all the file.
You can't, that just isn't how files work.
It sounds like you need some sort of message logging service / library that your program could connect to in order to log messages, which could then hide the underlying details of file opening / closing etc.
If each log line has a unique identifier (or even just line number), you could simply store in your log-parsing the identifier until which you got parsing. That way you don't have to change anything in the log file.
If the log file then starts to get too big, you could switch to a new one each day (for example).