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

lastModified() is returning seconds instead of milliseconds, causing blank Modified Dates on files #35

Closed
Highsight opened this issue Dec 29, 2021 · 1 comment · Fixed by #130
Labels
bug Something isn't working

Comments

@Highsight
Copy link

Jenkins and plugins versions report

Environment
Jenkins: 2.319.1
OS: Windows NT (unknown) - 10.0
---
Office-365-Connector:4.15.2
abort-downstream-builds:1.0
ace-editor:1.1
active-directory:2.25
analysis-model-api:10.8.1
ansicolor:1.0.1
ant:1.13
antisamy-markup-formatter:2.5
apache-httpcomponents-client-4-api:4.5.13-1.0
authentication-tokens:1.4
authorize-project:1.4.0
azure-artifact-manager:97.v074e1332e88d
azure-sdk:70.v63f6a95999a7
badge:1.9
blueocean-commons:1.25.2
blueocean-rest:1.25.2
bootstrap4-api:4.6.0-3
bootstrap5-api:5.1.3-3
bouncycastle-api:2.25
branch-api:2.7.0
build-name-setter:2.2.0
build-symlink:1.1
build-timeout:1.20
build-timestamp:1.0.3
buildgraph-view:1.8
caffeine-api:2.9.2-29.v717aac953ff3
checks-api:1.7.2
cloudbees-folder:6.16
cobertura:1.17
code-coverage-api:2.0.4
command-launcher:1.6
conditional-buildstep:1.4.1
copyartifact:1.46.2
cppcheck:1.25
credentials:2.6.2
credentials-binding:1.27
dark-theme:155.v497c78bbdbb3
dashboard-view:2.18
data-tables-api:1.11.3-4
display-url-api:2.3.5
docker-commons:1.17
docker-workflow:1.26
durable-task:493.v195aefbb0ff2
dynamic_extended_choice_parameter:1.0.1
echarts-api:5.2.2-1
email-ext:2.86
embeddable-build-status:2.0.3
envinject:2.4.0
envinject-api:1.8
extended-choice-parameter:0.82
external-monitor-job:1.7
flexible-publish:0.16.1
font-awesome-api:5.15.4-4
forensics-api:1.7.0
git:4.10.1
git-client:3.10.0
git-server:1.10
github:1.34.1
github-api:1.301-378.v9807bd746da5
github-branch-source:2.11.3
greenballs:1.15.1
groovy:2.4
groovy-label-assignment:1.2.0
groovy-postbuild:2.5
handlebars:3.0.8
jackson2-api:2.13.0-230.v59243c64b0a5
javadoc:1.6
jaxb:2.3.0.1
jdk-tool:1.5
jjwt-api:0.11.2-9.c8b45b8bb173
jobConfigHistory:2.28.1
jquery:1.12.4-1
jquery-detached:1.2.1
jquery3-api:3.6.0-2
jsch:0.1.55.2
junit:1.53
ldap:2.7
lockable-resources:2.12
log-parser:2.1
mailer:1.34
mapdb-api:1.0.9.0
matrix-auth:2.6.11
matrix-project:1.19
maven-plugin:3.15.1
momentjs:1.1.1
msbuild:1.30
multiple-scms:0.8
naginator:1.18.1
nodelabelparameter:1.10.1
okhttp-api:4.9.3-105.vb96869f8ac3a
pam-auth:1.6.1
parameterized-trigger:2.42
permissive-script-security:0.7
pipeline-build-step:2.15
pipeline-github-lib:1.0
pipeline-graph-analysis:1.12
pipeline-input-step:427.va6441fa17010
pipeline-milestone-step:1.3.2
pipeline-model-api:1.9.3
pipeline-model-definition:1.9.3
pipeline-model-extensions:1.9.3
pipeline-rest-api:2.19
pipeline-stage-step:2.5
pipeline-stage-tags-metadata:1.9.3
pipeline-stage-view:2.19
plain-credentials:1.7
plugin-util-api:2.6.0
popper-api:1.16.1-2
popper2-api:2.10.2-1
powershell:1.7
preSCMbuildstep:0.3
prism-api:1.25.0-1
promoted-builds:3.11
rebuild:1.32
resource-disposer:0.16
role-strategy:3.2.0
run-condition:1.5
scm-api:2.6.5
script-security:1.78
shelve-project-plugin:3.2
simple-theme-plugin:0.7
snakeyaml-api:1.29.1
ssh-credentials:1.19
sshd:3.1.0
structs:308.v852b473a2b8c
subscribe-build:0.99
subversion:2.15.1
theme-manager:0.6
throttle-concurrents:2.5
timestamper:1.15
token-macro:267.vcdaea6462991
trilead-api:1.0.13
validating-string-parameter:2.8
warnings-ng:9.10.2
windows-azure-storage:365.vf41653c43b01
windows-slaves:1.8
workflow-aggregator:2.6
workflow-api:1105.v3de5e2efac97
workflow-basic-steps:2.24
workflow-cps:2644.v29a793dac95a
workflow-cps-global-lib:552.vd9cc05b8a2e1
workflow-durable-task-step:1102.v9c8d2f466adb
workflow-job:2.42
workflow-multibranch:2.26
workflow-scm-step:2.13
workflow-step-api:613.v375732a042b1
workflow-support:3.8
ws-cleanup:0.40-SNAPSHOT (private-c04a2409)

What Operating System are you using (both controller, and any agents involved in the problem)?

Windows Server 2019

Reproduction steps

  1. Archive any file in a job
  2. Use Copy Artifacts plugin to pull down the artifacts in another job.
  3. The Modified Date for the file will be blank.
    image

Expected Results

The downloaded file should have its Modified Date filled out.

Actual Results

The downloaded file has a blank Modified Date.

Anything else?

This can be fixed (with a minimal loss of precision) by multiplying lastModified.toEpochSecond() by 1000 in lastModified(). Here's how I handled it in AzureBlobVirtualFile.java

    private static final int SECOND_TO_MILLISECOND_CONVERSION = 1000;
    @Override
    public long lastModified() throws IOException {
        String keyS = key + "/";
        CacheFrame frame = findCacheFrame(keyS);
        if (frame != null) {
            String rel = stripTrailingSlash(keyS.substring(frame.root.length()));
            CachedMetadata metadata = frame.children.get(rel);
            LOGGER.log(Level.FINER, "cache hit on lastModified of {0} / {1}", new Object[] {container, key});
            return metadata != null ? metadata.lastModified : 0;
        }

        if (isDirectory()) {
            return 0;
        }

        StorageAccountInfo accountInfo = Utils.getStorageAccount(build.getParent());
        try {
            BlobContainerClient blobContainerReference = Utils.getBlobContainerReference(accountInfo, this.container,
                    false);
            BlobClient blockBlobReference = blobContainerReference.getBlobClient(this.key);
            BlobProperties properties = blockBlobReference.getProperties();
            OffsetDateTime lastModified = properties.getLastModified();
            return lastModified == null ? 0
                    : (lastModified.toEpochSecond() * SECOND_TO_MILLISECOND_CONVERSION);
        } catch (URISyntaxException e) {
            throw new IOException(e);
        } catch (BlobStorageException e) {
            if (e.getStatusCode() == NOT_FOUND) {
                return 0;
            }
            // drop the cause in case there's unserializable fields
            throw new IOException(e.getMessage());
        }
    }

(Apologies for no PR, same as with the last bug I helped with, my company doesn't have an official GitHub account)

@Highsight Highsight added the bug Something isn't working label Dec 29, 2021
@panicking
Copy link
Contributor

@Highsight I'm preparing the PR

panicking added a commit to panicking/azure-artifact-manager-plugin that referenced this issue Dec 16, 2024
… of milliseconds

Fix the issue reported in:
jenkinsci#35

Signed-off-by: Michael Trimarchi <[email protected]>
timja pushed a commit that referenced this issue Dec 16, 2024
… of milliseconds (#130)

Fix the issue reported in:
#35

Signed-off-by: Michael Trimarchi <[email protected]>
@timja timja closed this as completed Dec 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
3 participants