Skip to content

Commit fdbb68a

Browse files
author
Robin McCorkell
committed
Return ? if mtime is 0 or -1
Tooltip contains 'Unable to determine date'. Fixes #6395
1 parent 5f66cb3 commit fdbb68a

3 files changed

Lines changed: 30 additions & 4 deletions

File tree

apps/files/js/filelist.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -637,12 +637,16 @@
637637
icon = OC.Util.replaceSVGIcon(fileData.icon),
638638
name = fileData.name,
639639
type = fileData.type || 'file',
640-
mtime = parseInt(fileData.mtime, 10) || new Date().getTime(),
640+
mtime = parseInt(fileData.mtime, 10),
641641
mime = fileData.mimetype,
642642
path = fileData.path,
643643
linkUrl;
644644
options = options || {};
645645

646+
if (isNaN(mtime)) {
647+
mtime = new Date().getTime()
648+
}
649+
646650
if (type === 'dir') {
647651
mime = mime || 'httpd/unix-directory';
648652
}
@@ -753,12 +757,21 @@
753757
if (modifiedColor >= '160') {
754758
modifiedColor = 160;
755759
}
760+
var formatted;
761+
var text;
762+
if (mtime > 0) {
763+
formatted = formatDate(mtime);
764+
text = OC.Util.relativeModifiedDate(mtime);
765+
} else {
766+
formatted = t('files', 'Unable to determine date');
767+
text = '?';
768+
}
756769
td = $('<td></td>').attr({ "class": "date" });
757770
td.append($('<span></span>').attr({
758771
"class": "modified",
759-
"title": formatDate(mtime),
772+
"title": formatted,
760773
"style": 'color:rgb('+modifiedColor+','+modifiedColor+','+modifiedColor+')'
761-
}).text(OC.Util.relativeModifiedDate(mtime)));
774+
}).text(text));
762775
tr.find('.filesize').text(simpleSize);
763776
tr.append(td);
764777
return tr;

apps/files/tests/js/filelistSpec.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ describe('OCA.Files.FileList tests', function() {
183183
expect($tr.find('.nametext').text().trim()).toEqual('testName.txt');
184184

185185
expect($tr.find('.filesize').text()).toEqual('1 kB');
186+
expect($tr.find('.date').text()).not.toEqual('?');
186187
expect(fileList.findFileEl('testName.txt')[0]).toEqual($tr[0]);
187188
});
188189
it('generates dir element with correct attributes when calling add() with dir data', function() {
@@ -209,6 +210,7 @@ describe('OCA.Files.FileList tests', function() {
209210
expect($tr.attr('data-mtime')).toEqual('123456');
210211

211212
expect($tr.find('.filesize').text()).toEqual('1 kB');
213+
expect($tr.find('.date').text()).not.toEqual('?');
212214

213215
expect(fileList.findFileEl('testFolder')[0]).toEqual($tr[0]);
214216
});
@@ -233,6 +235,7 @@ describe('OCA.Files.FileList tests', function() {
233235
expect($tr.attr('data-mtime')).toEqual('123456');
234236

235237
expect($tr.find('.filesize').text()).toEqual('Pending');
238+
expect($tr.find('.date').text()).not.toEqual('?');
236239
});
237240
it('generates dir element with default attributes when calling add() with minimal data', function() {
238241
var fileData = {
@@ -254,6 +257,7 @@ describe('OCA.Files.FileList tests', function() {
254257
expect($tr.attr('data-mtime')).toEqual('123456');
255258

256259
expect($tr.find('.filesize').text()).toEqual('Pending');
260+
expect($tr.find('.date').text()).not.toEqual('?');
257261
});
258262
it('generates file element with zero size when size is explicitly zero', function() {
259263
var fileData = {
@@ -264,6 +268,15 @@ describe('OCA.Files.FileList tests', function() {
264268
var $tr = fileList.add(fileData);
265269
expect($tr.find('.filesize').text()).toEqual('0 kB');
266270
});
271+
it('generates file element with unknown date when mtime invalid', function() {
272+
var fileData = {
273+
type: 'dir',
274+
name: 'testFolder',
275+
mtime: -1
276+
};
277+
var $tr = fileList.add(fileData);
278+
expect($tr.find('.date').text()).toEqual('?');
279+
});
267280
it('adds new file to the end of the list', function() {
268281
var $tr;
269282
var fileData = {

lib/private/files/storage/common.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public function getPermissions($path) {
132132

133133
public function filemtime($path) {
134134
$stat = $this->stat($path);
135-
if (isset($stat['mtime'])) {
135+
if (isset($stat['mtime']) && $stat['mtime'] > 0) {
136136
return $stat['mtime'];
137137
} else {
138138
return 0;

0 commit comments

Comments
 (0)