Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add file age check and maxage parameter for synchronization #37

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

stephdl
Copy link
Collaborator

@stephdl stephdl commented Feb 5, 2025

Introduce a file age check and a maxage parameter to optimize synchronization by determining the age of the timestamp file. This enhancement allows for more efficient handling of synchronization tasks.

Refs NethServer/dev#7296

FIRSTRUN="false"
fi
# retrieve unixtimestamp
date +"%Y-%m-%d %H:%M:%S" > /etc/imapsync/${task_id}.timestamp
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At this point it is better to store the timestamp value in a script variable, then write the timestamp only after a successful imapsync run. If flock or imapsync fail, the timestamp should not be written.

Suggested change
date +"%Y-%m-%d %H:%M:%S" > /etc/imapsync/${task_id}.timestamp
timestamp="$(date +%s)"

Furthermore, writing a timestamp string in the file is not necessary because the stat command reads the file metadata.

Suggested change
date +"%Y-%m-%d %H:%M:%S" > /etc/imapsync/${task_id}.timestamp
touch -m -d "@${timestamp}" /etc/imapsync/${task_id}.timestamp

get_file_age_in_days() {
local filename="$1"
# Get last access time in Unix timestamp
local last_access=$(stat -c %X "$filename")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

%Y is for data modification time. %X, access time is not reliable.

Suggested change
local last_access=$(stat -c %X "$filename")
local last_access=$(stat -c %Y "$filename")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants